home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume90 / aplictns / dkbtrace / part02 < prev    next >
Encoding:
Internet Message Format  |  1990-09-03  |  67.3 KB

  1. Path: abcfd20.larc.nasa.gov!amiga-request
  2. From: amiga-request@abcfd20.larc.nasa.gov (Amiga Sources/Binaries Moderator)
  3. Subject: v90i250: DKBTrace 2.01 - DKBtrace Ray-Tracer, Part02/10
  4. Reply-To: David Schanen <mtv@milton.u.washington.edu>
  5. Newsgroups: comp.sources.amiga
  6. Message-ID: <comp.sources.amiga:v90i250@abcfd20.larc.nasa.gov>
  7. References: <comp.sources.amiga:v90i249@abcfd20.larc.nasa.gov>
  8. Date: 03 Sep 90 23:21:37 GMT
  9. Approved: tadguy@uunet.UU.NET (Tad Guy)
  10. X-Mail-Submissions-To: amiga@uunet.uu.net
  11. X-Post-Discussions-To: comp.sys.amiga
  12.  
  13. Submitted-by: David Schanen <mtv@milton.u.washington.edu>
  14. Posting-number: Volume 90, Issue 250
  15. Archive-name: applications/dkbtrace-2.01/part02
  16.  
  17. #!/bin/sh
  18. # This is a shell archive.  Remove anything before this line, then unpack
  19. # it by saving it into a file and typing "sh file".  To overwrite existing
  20. # files, type "sh file -c".  You can also feed this as standard input via
  21. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  22. # will see the following message at the end:
  23. #        "End of archive 2 (of 10)."
  24. # Contents:  Docs/12to20.doc Docs/BasicShapes.data Docs/unixmakefile
  25. #   src/Dump2RGB.c src/gio.c src/ilbmw.c src/makefile src/palette.c
  26. #   src/prioq.c src/raw.c src/showprioq.c
  27. # Wrapped by tadguy@abcfd20 on Mon Sep  3 19:21:16 1990
  28. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  29. if test -f 'Docs/12to20.doc' -a "${1}" != "-c" ; then 
  30.   echo shar: Will not clobber existing file \"'Docs/12to20.doc'\"
  31. else
  32. echo shar: Extracting \"'Docs/12to20.doc'\" \(6186 characters\)
  33. sed "s/^X//" >'Docs/12to20.doc' <<'END_OF_FILE'
  34. XData file conversion from DKB 1.2 to 2.0 guidelines:
  35. X
  36. XThe only MANDATORY conversion(s) will be to data files that contain CSG
  37. X"DIFFERENCE" types.  The previous format required you to list the primary
  38. Xobject last, with the previous entries "subtracted" from the last object.
  39. XThe new format requires the primary object to be specified first, then
  40. Xthe other shapes to be subtracted follow.  This is more intuitive, and more
  41. Xlike a subtraction equation.  Subtractions performed by "INVERT" 'ing various
  42. Xobjects rather than specifically by the "DIFFERENCE" function are O.K. as is.
  43. X
  44. XThe Old Way:
  45. X
  46. XOBJECT
  47. X   DIFFERENCE
  48. X      subtracted shape 1
  49. X      subtracted shape 2
  50. X      subtracted shape 3
  51. X      subtracted shape 4
  52. X      orignal starting shape
  53. X   END_DIFFERENCE
  54. X.
  55. X.
  56. XEND_OBJECT
  57. X
  58. X
  59. XThe New Way:
  60. X
  61. XOBJECT
  62. X   DIFFERENCE
  63. X      orignal starting shape
  64. X      subtracted shape 1
  65. X      subtracted shape 2
  66. X      subtracted shape 3
  67. X      subtracted shape 4
  68. X   END_DIFFERENCE
  69. X.
  70. X.
  71. XEND_OBJECT
  72. X
  73. X
  74. XOther changes not required, but HIGHLY recommended (for speed), are to replace
  75. Xthe slower general QUADRIC types with the new primitive types SPHERE and
  76. XPLANE, when possible.
  77. X
  78. X
  79. X
  80. XSPHERES:
  81. X
  82. XA "Sphere" QUADRIC is effectively "built" around the origin with a default
  83. Xsize (radius) of 1.0.  SCALE functions will become the sphere's radius, while
  84. XTRANSLATE functions will become the sphere's new "origin" or center.
  85. X
  86. XNOTE:  This will only work for symmetrically scaled spheres (where all 3 SCALE
  87. X       values are the same).  For oblate sphereoids, you will still need to
  88. X       use the general QUADRIC type.  SPHERES cannot be "stretched" properly.
  89. X
  90. XThe simplest conversion is:
  91. X
  92. XOld:  QUADRIC "Sphere" SCALE <10.0 10.0 10.0> END_QUADRIC
  93. X
  94. XNew:  SPHERE <0.0 0.0 0.0> 10.0 END_SPHERE
  95. X
  96. XThis will then generate a true sphere at the origin (<0.0 0.0 0.0>), and of
  97. Xthe size indicated (10).  Any previous TRANSLATE or ROTATE (or even SCALE)
  98. Xcommands will still work properly.  To not change any of the SCALE statements,
  99. Xetc. you should specify a radius of 1.0, then all object transformations will
  100. Xoccur exactly as they did previously.
  101. X
  102. XAnother conversion you can make is to include any TRANSLATE statements into
  103. Xthe "center" statement of the sphere.
  104. X
  105. XOld:  QUADRIC "Sphere" TRANSLATE <3.0 10.0 5.0> END_QUADRIC
  106. X
  107. XNew:  SPHERE <3.0 10.0 5.0> 1.0 END_SPHERE
  108. X
  109. XThis will then generate a true sphere at the origin indicated, with the
  110. Xdefault radius of 1.0.  Any further previous TRANSLATE or ROTATE (or even
  111. XSCALE) commands will work as expected.
  112. X
  113. X
  114. X
  115. XPLANES:
  116. X
  117. XA "Plane_xx" QUADRIC is effectively "built" at the origin, but extends in
  118. Xany two  of three dimensions (Plane_XY, Plane_XZ, etc).  You must determine
  119. Xthe plane's orientation:  for easy figuring, the dimension NOT specified in
  120. Xthe old name of the plane is the direction of the "UP" vector for the new
  121. XPLANE primitive.  Translate values may be changed into the "how far up is UP"
  122. Xvalue for the PLANE primitive.
  123. X
  124. X(For example, in an "Plane_XZ", the "Y" axis is the unspecifed axis)
  125. X
  126. XOld:  QUADRIC "Plane_XZ" TRANSLATE <0.0 -5.0 0.0> END_QUADRIC
  127. X
  128. XSo, the "Y" axis becomes the "UP" vector, and the TRANSLATE gives us the "how
  129. Xfar up is UP" parameter:
  130. X
  131. XNew:  PLANE <0.0 1.0 0.0> -5.0 END_PLANE
  132. X          |        |
  133. X "UP" direction --         -- "How far up is UP?" 
  134. X  on the Y axis
  135. X
  136. XThis will then generate a true plane in the direction(s) indicated, and trans-
  137. Xlate it up (or down, in this example) along the "UP" vector.  Any previous
  138. XTRANSLATE or ROTATE (or even SCALE) commands will work properly.  To not
  139. Xchange any of the TRANSLATE, etc. statements, the "how far up" parameter
  140. Xshould be 0.0 (make the plane on the "origin" of <0.0 0.0 0.0>), then any
  141. Xtransformations will work as before.
  142. X
  143. XNOTE:  PLANES, like their QUADRIC counterparts, extend out to infinity.  If
  144. X       you desire a "clipped" plane (one of finite size) it is easiest to
  145. X       define two TRIANGLE primitives, laid so their hypotenuse(s) are back
  146. X       to back.
  147. X
  148. X
  149. X
  150. XLIGHT SOURCES:
  151. X
  152. XOne important thing to remember when defining a LIGHT_SOURCE is this:  The
  153. Xcenter of the light source MUST be "TRANSLATED" to wherever you want the point
  154. Xsource to be.  Simply specifying the "origin" of the sphere to be there DOES
  155. XNOT WORK, although it seems as though is should.  Light sources being
  156. Xconverted to SPHERE types from QUADRIC types should be defined about the
  157. X<0.0 0.0 0.0> origin, with the appropriate radius taken from any SCALE
  158. Xstatements, but MUST then be "TRANSLATE" 'ed to wherever you want the light
  159. Xto be.  Chances are, due to the fact that QUADRIC "Spheres" are generated
  160. Xcentered about the <0.0 0.0 0.0> origin, there will already be the proper
  161. X"TRANSLATE" statement there in the object's definition.
  162. X
  163. XOld:
  164. X
  165. XOBJECT
  166. X    QUADRIC "Sphere" SCALE <2.0 2.0 2.0> END_QUADRIC
  167. X    TRANSLATE <0.0 200.0 0.0>
  168. X    LIGHT_SOURCE
  169. X    .
  170. X    .
  171. XEND_OBJECT
  172. X
  173. XNew:
  174. X
  175. XOBJECT
  176. X    SPHERE <0.0 0.0 0.0> 2.0 END_SPHERE
  177. X    TRANSLATE <0.0 200.0 0.0>
  178. X    LIGHT_SOURCE
  179. X    .
  180. X    .
  181. XEND_OBJECT
  182. X
  183. X
  184. X
  185. XIMAGE QUALITY
  186. X
  187. XA new added feature for speed of tracing is the Quality parameter:
  188. X
  189. XQ1 = Basic object positions only, nothing but Ambient Light illumination.
  190. XQ3 = All of the above, plus Diffuse Lighting of objects.
  191. XQ5 = All of the above, plus Shadows from Light Sources and Highlights.
  192. XQ7 = All of the above, plus Textures.
  193. XQ9 = All of the above, plus Reflection, Refraction, and Transmittance.
  194. X
  195. XThe values in-between are reserved for future expansion.  Using a lower
  196. Xquality value is great for quick renderings just to see where the heck the
  197. Xvarious objects you have defined wind up.
  198. X
  199. XOne important thing to note about Quality:  If you have a textured object in
  200. Xyour scene, you probably didn't give the basic object a COLOUR.  If you plan
  201. Xon rendering it with the "Quality" factor less than 7, you _MUST_ declare a
  202. XCOLOUR for the object in addition to the texture, if it is to be visible.
  203. XThis is so the ambient or diffuse light has some colour on the object to hit
  204. Xwhile the surface texture is turned off.  When you finally render with Quality
  205. Xof 7 or greater, the defined basic object colour will not be seen, but rather
  206. Xyour intended texture.
  207. X
  208. X
  209. X
  210. XNot too horrible, eh?  -  Enjoy the plethora of new features and increased
  211. XSPEED of DKB 2.0 !
  212. END_OF_FILE
  213. if test 6186 -ne `wc -c <'Docs/12to20.doc'`; then
  214.     echo shar: \"'Docs/12to20.doc'\" unpacked with wrong size!
  215. fi
  216. # end of 'Docs/12to20.doc'
  217. fi
  218. if test -f 'Docs/BasicShapes.data' -a "${1}" != "-c" ; then 
  219.   echo shar: Will not clobber existing file \"'Docs/BasicShapes.data'\"
  220. else
  221. echo shar: Extracting \"'Docs/BasicShapes.data'\" \(4415 characters\)
  222. sed "s/^X//" >'Docs/BasicShapes.data' <<'END_OF_FILE'
  223. XDECLARE Sphere = QUADRIC
  224. X       <1.0 1.0 1.0>
  225. X       <0.0 0.0 0.0>
  226. X       <0.0 0.0 0.0>
  227. X       -1.0
  228. XEND_QUADRIC
  229. X
  230. XDECLARE Cylinder_X = QUADRIC
  231. X       <0.0 1.0 1.0>
  232. X       <0.0 0.0 0.0>
  233. X       <0.0 0.0 0.0>
  234. X       -1.0
  235. XEND_QUADRIC
  236. X
  237. XDECLARE Cylinder_Y = QUADRIC
  238. X       <1.0 0.0 1.0>
  239. X       <0.0 0.0 0.0>
  240. X       <0.0 0.0 0.0>
  241. X       -1.0
  242. XEND_QUADRIC
  243. X
  244. XDECLARE Cylinder_Z = QUADRIC
  245. X       <1.0 1.0 0.0>
  246. X       <0.0 0.0 0.0>
  247. X       <0.0 0.0 0.0>
  248. X       -1.0
  249. XEND_QUADRIC
  250. X
  251. XDECLARE Cone_X = QUADRIC
  252. X       <0.0 1.0 1.0>
  253. X       <0.0 0.0 0.0>
  254. X       <1.0 0.0 0.0>
  255. X       0.0
  256. XEND_QUADRIC
  257. X
  258. XDECLARE Cone_Y = QUADRIC
  259. X       <1.0 0.0 1.0>
  260. X       <0.0 0.0 0.0>
  261. X       <0.0 1.0 0.0>
  262. X       0.0
  263. XEND_QUADRIC
  264. X
  265. XDECLARE Cone_Z = QUADRIC
  266. X       <1.0 1.0 0.0>
  267. X       <0.0 0.0 0.0>
  268. X       <0.0 0.0 1.0>
  269. X       0.0
  270. XEND_QUADRIC
  271. X
  272. XDECLARE Plane_YZ = QUADRIC
  273. X       <0.0 0.0 0.0>
  274. X       <0.0 0.0 0.0>
  275. X       <1.0 0.0 0.0>
  276. X       0.0
  277. XEND_QUADRIC
  278. X       
  279. XDECLARE Plane_XZ = QUADRIC
  280. X       <0.0 0.0 0.0>
  281. X       <0.0 0.0 0.0>
  282. X       <0.0 1.0 0.0>
  283. X       0.0
  284. XEND_QUADRIC
  285. X       
  286. XDECLARE Plane_XY = QUADRIC
  287. X       <0.0 0.0 0.0>
  288. X       <0.0 0.0 0.0>
  289. X       <0.0 0.0 1.0>
  290. X       0.0
  291. XEND_QUADRIC
  292. X
  293. X
  294. X{ y^2 + z^2 - x = 0 }
  295. XDECLARE Paraboloid_X = QUADRIC
  296. X       <0.0  1.0  1.0>
  297. X       <0.0  0.0  0.0>
  298. X       <-1.0 0.0  0.0>
  299. X       0.0
  300. XEND_QUADRIC
  301. X
  302. X
  303. X{ x^2 + z^2 - y = 0 }
  304. XDECLARE Paraboloid_Y = QUADRIC
  305. X       <1.0  0.0  1.0>
  306. X       <0.0  0.0  0.0>
  307. X       <0.0 -1.0  0.0>
  308. X       0.0
  309. XEND_QUADRIC
  310. X
  311. X
  312. X{ x^2 + y^2 - z = 0 }
  313. XDECLARE Paraboloid_Z = QUADRIC
  314. X       <1.0  1.0  0.0>
  315. X       <0.0  0.0  0.0>
  316. X       <0.0  0.0 -1.0>
  317. X       0.0
  318. XEND_QUADRIC
  319. X
  320. X
  321. X{ y - x^2 + z^2 = 0 }
  322. XDECLARE Hyperboloid = QUADRIC
  323. X       < -1.0  0.0  1.0>
  324. X       <  0.0  0.0  0.0>
  325. X       <  0.0  1.0  0.0>
  326. X       0.0
  327. XEND_QUADRIC
  328. X
  329. XDECLARE Black = COLOUR RED 0.0 GREEN 0.0 BLUE 0.0
  330. XDECLARE White = COLOUR RED 1.0 GREEN 1.0 BLUE 1.0
  331. XDECLARE Red = COLOUR RED 1.0
  332. XDECLARE Green = COLOUR GREEN 1.0
  333. XDECLARE Blue = COLOUR BLUE 1.0
  334. XDECLARE Yellow = COLOUR RED 1.0 GREEN 1.0
  335. XDECLARE Cyan = COLOUR BLUE 1.0 GREEN 1.0
  336. XDECLARE Magenta = COLOUR RED 1.0 BLUE 1.0
  337. X
  338. XDECLARE Red_Marble = TEXTURE
  339. X   MARBLE
  340. X   TURBULENCE 1.0
  341. X   COLOUR_MAP
  342. X        [0.0 0.8  COLOUR RED 0.8 GREEN 0.8 BLUE 0.6
  343. X                COLOUR RED 0.8 GREEN 0.4 BLUE 0.4]
  344. X        [0.8 1.001 COLOUR RED 0.8 GREEN 0.4 BLUE 0.4
  345. X                COLOUR RED 0.8 GREEN 0.2 BLUE 0.2]
  346. X    END_COLOUR_MAP
  347. X    SCALE <10.0 10.0 10.0>
  348. XEND_TEXTURE
  349. X
  350. XDECLARE Brown_Agate = TEXTURE
  351. X     AGATE
  352. X     TURBULENCE 0.3
  353. X     COLOUR_MAP
  354. X          [0.0 0.5  COLOUR RED 1.0 GREEN 1.0 BLUE 1.0
  355. X                  COLOUR RED 0.9 GREEN 0.7 BLUE 0.6]
  356. X          [0.5 0.6  COLOUR RED 0.9 GREEN 0.7 BLUE 0.6
  357. X                  COLOUR RED 0.9 GREEN 0.7 BLUE 0.4]
  358. X          [0.6 1.001 COLOUR RED 0.9 GREEN 0.7 BLUE 0.4
  359. X                  COLOUR RED 0.7 GREEN 0.4 BLUE 0.2]
  360. X      END_COLOUR_MAP
  361. X      SCALE <10.0 10.0 10.0>
  362. XEND_TEXTURE
  363. X
  364. XDECLARE Blue_Marble = TEXTURE
  365. X    AGATE
  366. X    TURBULENCE 0.3
  367. X    COLOUR_MAP
  368. X          [0.0 0.5  COLOUR RED 0.30 GREEN 0.30 BLUE 0.50
  369. X                  COLOUR RED 0.30 GREEN 0.30 BLUE 0.50]
  370. X          [0.5 0.55 COLOUR RED 0.30 GREEN 0.30 BLUE 0.50
  371. X                  COLOUR RED 0.20 GREEN 0.20 BLUE 0.30]
  372. X          [0.55 0.6 COLOUR RED 0.20 GREEN 0.20 BLUE 0.30
  373. X                  COLOUR RED 0.25 GREEN 0.25 BLUE 0.35]
  374. X          [0.6 0.7  COLOUR RED 0.25 GREEN 0.25 BLUE 0.35
  375. X                  COLOUR RED 0.15 GREEN 0.15 BLUE 0.26]
  376. X          [0.7 0.8  COLOUR RED 0.15 GREEN 0.15 BLUE 0.26
  377. X                  COLOUR RED 0.10 GREEN 0.10 BLUE 0.20]
  378. X          [0.8 0.9  COLOUR RED 0.10 GREEN 0.10 BLUE 0.20
  379. X                  COLOUR RED 0.30 GREEN 0.30 BLUE 0.50]
  380. X          [0.9 1.001  COLOUR RED 0.30 GREEN 0.30 BLUE 0.50
  381. X                  COLOUR RED 0.10 GREEN 0.10 BLUE 0.20]
  382. X    END_COLOUR_MAP
  383. X    SCALE <10.0 10.0 10.0>
  384. XEND_TEXTURE
  385. X
  386. XDECLARE Dull = TEXTURE
  387. X   AMBIENT 0.3
  388. X   DIFFUSE 0.7
  389. XEND_TEXTURE
  390. X
  391. XDECLARE Shiny = TEXTURE
  392. X   AMBIENT 0.3
  393. X   DIFFUSE 0.7
  394. X   PHONG 1.0
  395. X   PHONGSIZE 20.0
  396. XEND_TEXTURE
  397. X
  398. XDECLARE Mirror = TEXTURE
  399. X   AMBIENT 0.0
  400. X   DIFFUSE 0.0
  401. X   REFLECTION 1.0
  402. XEND_TEXTURE
  403. X
  404. XDECLARE Luminous = TEXTURE
  405. X   AMBIENT 1.0
  406. X   DIFFUSE 0.0
  407. XEND_TEXTURE
  408. X
  409. XDECLARE Glass = TEXTURE
  410. X   AMBIENT 0.0
  411. X   DIFFUSE 0.0
  412. X   REFLECTION 0.5
  413. X   REFRACTION 0.5
  414. X   IOR 1.2
  415. XEND_TEXTURE
  416. X
  417. XDECLARE Metal = TEXTURE
  418. X   AMBIENT 0.3
  419. X   DIFFUSE 0.7
  420. X   BRILLIANCE 6.0
  421. XEND_TEXTURE
  422. X
  423. XDECLARE Glass2 = TEXTURE
  424. X   AMBIENT 0.0
  425. X   DIFFUSE 0.0
  426. X   REFLECTION 0.5
  427. X   REFRACTION 0.5
  428. XEND_TEXTURE
  429. END_OF_FILE
  430. if test 4415 -ne `wc -c <'Docs/BasicShapes.data'`; then
  431.     echo shar: \"'Docs/BasicShapes.data'\" unpacked with wrong size!
  432. fi
  433. # end of 'Docs/BasicShapes.data'
  434. fi
  435. if test -f 'Docs/unixmakefile' -a "${1}" != "-c" ; then 
  436.   echo shar: Will not clobber existing file \"'Docs/unixmakefile'\"
  437. else
  438. echo shar: Extracting \"'Docs/unixmakefile'\" \(6342 characters\)
  439. sed "s/^X//" >'Docs/unixmakefile' <<'END_OF_FILE'
  440. X# Makefile for DKB Ray Tracing Program by David Buck and Aaron Collins
  441. X# This file is released to the public domain.
  442. X#
  443. X#
  444. X# MAKE Macros and Such...
  445. X#
  446. X
  447. X#***************************************************************
  448. X#*
  449. X#*                      Amiga Options
  450. X#*
  451. X#***************************************************************
  452. X
  453. X# Uncomment for Amiga Lattice C FFP
  454. X#CFLAGS    = -cusrft -ff -m0 -q5w5e -b0 -O -v
  455. X#DUMPFLAGS    = -cusrt -ff -m0 -q5w5e -O -v
  456. X
  457. X# Uncomment for Amiga Lattice C with 68881
  458. X#CFLAGS    = -cusrft -f8 -m2 -q5w5e -b0 -O -v
  459. X
  460. X# Flags for debugging
  461. X# CFLAGS    = -cusrft -f8 -m2 -b0 -q5w5e -d5 -v
  462. X
  463. X#LIBSFFP    = lib:lcmffp.lib lib:lcnb.lib lib:amiga.lib
  464. X#LIBS881    = lib:lcm881.lib lib:lcnb.lib lib:amiga.lib
  465. XOBJ    = o
  466. XMACHINE_OBJ    = unix.$(OBJ)
  467. XCFLAGS=        -c -O
  468. XLFLAGS =    -o dkbtrace -O
  469. X
  470. X
  471. X# Make's implicit rules for making a .o file from a .c file...
  472. X#
  473. X.c.o :
  474. X    $(CC) $(CFLAGS) $*.c
  475. X
  476. X# Generic "Unix" MAKE's implicit rules for making a .OBJ file from a .C file
  477. X#
  478. X#*.o : *.c
  479. X#    $(CC) $(CFLAGS) $*
  480. X
  481. X#***************************************************************
  482. X#*
  483. X#*                      IBM Options
  484. X#*
  485. X#***************************************************************
  486. X
  487. X# Note for the IBM Version:
  488. X# Uses system environment variable LIB for the linker's .LIB file path.
  489. X# (Example:  Set LIB=C:\LIB)  if you change this the two .LNK files will also
  490. X# need to be changed as well.  The system environment variable CMODEL also
  491. X# may be defined for the memory model of the compiler.  DKBTrace requires
  492. X# the "Large" memory model.  (Example Set CMODEL=l)  If you don't want to
  493. X# use the DOS environment variables, uncomment the following two lines:
  494. X
  495. X#CMODEL    =l
  496. X#LIB    =c:\lib
  497. X
  498. X#CC    =tcc
  499. X#OBJ    =obj
  500. X#MACHINE_OBJ    = ibm.$(OBJ)
  501. X#
  502. X# Uncomment Turbo Link for Symbolic Debugging, or use DOS/MS-LINK for
  503. X# faster .EXE execution speed (shame on you, Borland, for no FARCALL!...)
  504. X# Note: you also must use a -v in the CFLAGS rather than -v- if you want
  505. X# to use the symbolic debugging facilities of Turbo-Debug.
  506. X
  507. X#TLINK    =tlink /l/v
  508. X#TLINK    =link /EXEPACK /PACKCODE /FARCALL
  509. X#
  510. X# IBM (Turbo-MAKE, actually) Specific MAKE Directives:
  511. X#
  512. X#
  513. X# Uncomment This for No Numeric Data Processor Extension (No Math Co)
  514. X#LINKFLAGS=$(LIB)\emu+$(LIB)\math$(CMODEL)+$(LIB)\c$(CMODEL);
  515. X#
  516. X# Uncomment This for NDP Extension (80x87 Co-Processor) Support
  517. X#LINKFLAGS=$(LIB)\fp87+$(LIB)\math$(CMODEL)+$(LIB)\c$(CMODEL);
  518. X#
  519. X
  520. X# Uncomment for 8086/8088 instruction set usage
  521. X#
  522. X#CFLAGS    =-m$(CMODEL) -r -K -G -O -Z -d -c -v- -k- -N-
  523. X
  524. X
  525. X# Uncomment for 80186/80268 (incl. V20!) instruction set usage
  526. X#
  527. X#CFLAGS    =-m$(CMODEL) -1 -a -r -K -G -O -Z -d -c -v- -k- -N-
  528. X
  529. X# Turbo-MAKE's implicit rules for making a .OBJ file from a .C file...
  530. X#
  531. X#.c.obj :
  532. X# $(CC) $(CFLAGS) $*
  533. X
  534. X# Generic "Unix" MAKE's implicit rules for making a .OBJ file from a .C file
  535. X#
  536. X#*.obj : *.c
  537. X#    $(CC) $(CFLAGS) $*
  538. X
  539. X
  540. X#***************************************************************
  541. X#*
  542. X#*                          Common  Stuff
  543. X#*
  544. X#***************************************************************
  545. X
  546. XDKBOBJS = trace.$(OBJ) render.$(OBJ) tokenize.$(OBJ) parse.$(OBJ) \
  547. X      objects.$(OBJ) spheres.$(OBJ) quadrics.$(OBJ) lighting.$(OBJ) \
  548. X      prioq.$(OBJ) texture.$(OBJ) matrices.$(OBJ) csg.$(OBJ) \
  549. X      colour.$(OBJ) viewpnt.$(OBJ) ray.$(OBJ) planes.$(OBJ) iff.$(OBJ) \
  550. X      gif.$(OBJ) gifdecod.$(OBJ) triangle.$(OBJ) raw.$(OBJ) $(MACHINE_OBJ)
  551. X
  552. X
  553. X#  Amiga Linkage...
  554. X#
  555. X#trace881:    $(DKBOBJS)
  556. X#    blink with withfile LIB $(LIBS881) TO trace881
  557. X
  558. X#traceffp:    $(DKBOBJS)
  559. X#    blink with withfile LIB $(LIBSFFP) TO traceffp
  560. X
  561. X#Sculpt2DKB:    Sculpt2DKB.o
  562. X#    blink lib:c.o Sculpt2DKB.o lib $(LIBSFFP) to Sculpt2DKB
  563. X
  564. X# IBM Linkage...
  565. X#
  566. X#dkb.exe : $(DKBOBJS)
  567. X#
  568. X
  569. X#$(TLINK) @dkb.lnk
  570. X
  571. X#Sculpt2DKB.exe : Sculpt2DKB.obj
  572. X#    $(TLINK) $(LIB)\c0$(CMODEL)+Sculpt2DKB,Sculpt2DKB,Sculpt2DKB/m,$(LINKFLAGS);
  573. X
  574. X#gluetga.exe : gluetga.obj
  575. X#    $(TLINK) $(LIB)\c0$(CMODEL)+gluetga,gluetga,gluetga/m,$(LINKFLAGS);
  576. X
  577. X#halftga.exe : halftga.obj
  578. X#    $(TLINK) $(LIB)\c0$(CMODEL)+halftga,halftga,halftga/m,$(LINKFLAGS);
  579. X
  580. Xdkbtrace:    $(DKBOBJS)
  581. X    cc $(LFLAGS) $(DKBOBJS) -lm
  582. X
  583. X#
  584. X# Specific module/header dependencies for DKBtrace:
  585. X#
  586. X
  587. XSculpt2DKB.$(OBJ) : Sculpt2DKB.c dkbproto.h frame.h
  588. X
  589. Xhalftga.$(OBJ) : halftga.c
  590. X
  591. Xgluetga.$(OBJ) : gluetga.c
  592. X
  593. Xtrace.$(OBJ) : trace.c dkbproto.h frame.h vector.h config.h
  594. X
  595. Xtokenize.$(OBJ) : tokenize.c dkbproto.h frame.h config.h
  596. X
  597. Xparse.$(OBJ) : parse.c dkbproto.h frame.h config.h
  598. X
  599. Xrender.$(OBJ) : render.c dkbproto.h frame.h vector.h config.h
  600. X
  601. Xlighting.$(OBJ) : lighting.c dkbproto.h frame.h vector.h config.h
  602. X
  603. Xprioq.$(OBJ) : prioq.c dkbproto.h frame.h config.h
  604. X
  605. Xtexture.$(OBJ) : texture.c dkbproto.h frame.h vector.h config.h
  606. X
  607. Xobjects.$(OBJ) : objects.c dkbproto.h frame.h vector.h config.h
  608. X
  609. Xspheres.$(OBJ) : spheres.c dkbproto.h frame.h vector.h config.h
  610. X
  611. Xplanes.$(OBJ) : planes.c dkbproto.h frame.h vector.h config.h
  612. X
  613. Xquadrics.$(OBJ) : quadrics.c dkbproto.h frame.h vector.h config.h
  614. X
  615. Xmatrices.$(OBJ) : matrices.c dkbproto.h frame.h vector.h config.h
  616. X
  617. Xcsg.$(OBJ) : csg.c dkbproto.h frame.h vector.h config.h
  618. X
  619. Xcolour.$(OBJ) : colour.c dkbproto.h frame.h config.h
  620. X
  621. Xviewpnt.$(OBJ) : viewpnt.c dkbproto.h frame.h vector.h config.h
  622. X
  623. Xray.$(OBJ) : ray.c dkbproto.h frame.h vector.h config.h
  624. X
  625. Xiff.$(OBJ) : iff.c dkbproto.h frame.h config.h
  626. X
  627. Xgif.$(OBJ) : gif.c dkbproto.h frame.h config.h
  628. X
  629. Xgifdecod.$(OBJ) : gifdecod.c dkbproto.h frame.h config.h
  630. X
  631. Xraw.$(OBJ) :    raw.c dkbproto.h frame.h config.h
  632. X
  633. Xtriangle.$(OBJ) : triangle.c dkbproto.h frame.h vector.h config.h
  634. X
  635. Xamiga.$(OBJ) :    amiga.c dkbproto.h frame.h config.h
  636. X
  637. Xibm.$(OBJ) :    ibm.c dkbproto.h frame.h config.h
  638. X
  639. Xunix.$(OBJ) :    unix.c dkbproto.h frame.h config.h
  640. X
  641. X
  642. X#
  643. X#
  644. X#  Utilities
  645. X#
  646. X
  647. X#  Amiga Linkage
  648. X#
  649. XDump2RGB:    Dump2RGB.o
  650. X        blink lib:c.o Dump2RGB.o LIB $(LIBSFFP) TO Dump2RGB
  651. X
  652. XDump2Raw:    Dump2Raw.o
  653. X        blink lib:c.o Dump2Raw.o LIB $(LIBSFFP) TO Dump2Raw
  654. X
  655. XDumpToIFF:    DumpToIFF.o palette.o showprioq.o gio.o iffw.o ilbmw.o putpict.o packer.o
  656. X        blink with dumpwithfile LIB $(LIBSFFP) TO DumpToIFF
  657. X
  658. XDumpToIFF.o:    DumpToIFF.c
  659. X        $(CC) $(DUMPFLAGS) $*
  660. X
  661. XDump2RGB.o:    Dump2RGB.c
  662. X
  663. XDump2Raw.o:    Dump2Raw.c
  664. X
  665. Xpalette.o:    palette.c showprioq.h
  666. X        $(CC) $(DUMPFLAGS) $*
  667. X
  668. Xshowprioq.o:    showprioq.c showprioq.h
  669. X        $(CC) $(DUMPFLAGS) $*
  670. X
  671. Xgio.o:        gio.c
  672. X        $(CC) $(DUMPFLAGS) $*
  673. X
  674. Xiffw.o:        iffw.c
  675. X        $(CC) $(DUMPFLAGS) $*
  676. X
  677. Xilbmw.o:        ilbmw.c
  678. X        $(CC) $(DUMPFLAGS) $*
  679. X
  680. Xputpict.o:        putpict.c
  681. X        $(CC) $(DUMPFLAGS) $*
  682. X
  683. Xpacker.o:        packer.c
  684. X        $(CC) $(DUMPFLAGS) $*
  685. END_OF_FILE
  686. if test 6342 -ne `wc -c <'Docs/unixmakefile'`; then
  687.     echo shar: \"'Docs/unixmakefile'\" unpacked with wrong size!
  688. fi
  689. # end of 'Docs/unixmakefile'
  690. fi
  691. if test -f 'src/Dump2RGB.c' -a "${1}" != "-c" ; then 
  692.   echo shar: Will not clobber existing file \"'src/Dump2RGB.c'\"
  693. else
  694. echo shar: Extracting \"'src/Dump2RGB.c'\" \(5693 characters\)
  695. sed "s/^X//" >'src/Dump2RGB.c' <<'END_OF_FILE'
  696. X#include "frame.h"
  697. X
  698. X/* #define IBM TRUE */
  699. X
  700. X#define Amiga TRUE
  701. X
  702. XIMAGE Raw_Image;
  703. X
  704. XFILE *fp, *palette_file, *output_palette_file;
  705. XFILE *fred, *fgrn, *fblu;
  706. Xchar input_filename[100], master_filename[100], output_filename[100];
  707. Xint image_width, image_height;
  708. X
  709. X#ifdef IBM
  710. X#define REDNAME "%s.r8"
  711. X#define GRNNAME "%s.g8"
  712. X#define BLUNAME "%s.b8"
  713. X#define DEFAULT_WIDTH  320
  714. X#define DEFAULT_HEIGHT 200
  715. X#endif
  716. X
  717. X#ifdef Amiga
  718. X#define REDNAME "%s.red"
  719. X#define GRNNAME "%s.grn"
  720. X#define BLUNAME "%s.blu"
  721. X#define DEFAULT_WIDTH  320
  722. X#define DEFAULT_HEIGHT 400
  723. X#endif
  724. X
  725. Xint read_raw_byte PARAMS((FILE *f));
  726. Xint read_raw_word PARAMS((FILE *f));
  727. Xvoid read_raw_image PARAMS((IMAGE *Image));
  728. Xvoid get_parameters PARAMS((int argc, char **argv));
  729. Xvoid OpenRGB PARAMS((void));
  730. Xvoid SaveRGB PARAMS((int red, int grn, int blu));
  731. X
  732. Xvoid main (argc, argv) 
  733. X   int argc;
  734. X   char **argv;
  735. X   {
  736. X   unsigned int x, y, index;
  737. X
  738. X   if (argc < 2)
  739. X     {
  740. X     printf ("\nUsage:  DumpToRGB [-wxxx -hxxx] <filename>\n   .dis extension is assumed for <filename>\n   default image size: %d x %d", DEFAULT_WIDTH, DEFAULT_HEIGHT);
  741. X     exit(0);
  742. X     }
  743. X
  744. X   fp = NULL;
  745. X
  746. X   get_parameters(argc, argv);
  747. X
  748. X   printf ("Reading raw file\n");
  749. X   read_raw_image (&Raw_Image);
  750. X
  751. X   printf ("Converting...\n");
  752. X
  753. X   OpenRGB();
  754. X   for (y = 0 ; y < Raw_Image.height ; y++) {
  755. X      for (x = 0 ; x < Raw_Image.width ; x++) {
  756. X         index = y*Raw_Image.width + x;
  757. X         SaveRGB((int)Raw_Image.red[index],(int)Raw_Image.green[index],(int)Raw_Image.blue[index]);
  758. X         }
  759. X      for (; x < image_width ; x++)
  760. X    SaveRGB(0, 0, 0);
  761. X      }
  762. X   for (; y < image_height ; y++)
  763. X      for (; x < image_width; x++)
  764. X    SaveRGB(0, 0, 0);
  765. X   fclose(fred);
  766. X   fclose(fgrn);
  767. X   fclose(fblu);
  768. X   }
  769. X
  770. Xvoid get_parameters (argc, argv)
  771. X   int argc;
  772. X   char **argv;
  773. X   {
  774. X   int i, filename_number;
  775. X
  776. X   image_height = DEFAULT_HEIGHT;
  777. X   image_width = DEFAULT_WIDTH;
  778. X
  779. X   filename_number = 0;
  780. X   for (i = 1 ; i < argc ; i++) {
  781. X
  782. X      if (argv[i][0] == '-')
  783. X     switch (argv[i][1]) {
  784. X        case 'w': sscanf(&argv[i][2], "%d", &image_height);
  785. X              break;
  786. X        case 'h': sscanf(&argv[i][2], "%d", &image_height);
  787. X              break;
  788. X        default : printf("Unknown option %s - proceeding...\n");
  789. X        }
  790. X      else
  791. X         switch (filename_number) {
  792. X            case 0: strcpy (master_filename, argv[i]);
  793. X            sprintf (input_filename, "%s.dis", master_filename);
  794. X            filename_number++;
  795. X                    break;
  796. X
  797. X            default: printf ("Too many filenames in commandline\n");
  798. X                     exit(1);
  799. X            }
  800. X      }
  801. X   }
  802. X
  803. X
  804. Xint read_raw_byte(f)
  805. X   FILE *f;
  806. X   {
  807. X   int c;
  808. X   if ((c = getc(f)) == EOF)
  809. X      return (-1);
  810. X   return (c);
  811. X   }
  812. X
  813. Xint read_raw_word(f)
  814. X   FILE *f;
  815. X   {
  816. X   int byte1, byte2;
  817. X
  818. X   byte1 = read_raw_byte(f);
  819. X   if (byte1 == -1)
  820. X      return(-1);
  821. X
  822. X   byte2 = read_raw_byte(f);
  823. X   if (byte2 == -1)
  824. X      return(-1);
  825. X
  826. X   return (byte1 + byte2*256);
  827. X   }
  828. X
  829. Xvoid OpenRGB()
  830. X{
  831. X   char nmbuff[200];
  832. X
  833. X   sprintf( nmbuff, REDNAME, master_filename );
  834. X   if ((fred = fopen(nmbuff, "wb")) == NULL) {
  835. X      printf ("Cannot open red output file for %s\n", master_filename);
  836. X      exit(1);
  837. X      }
  838. X
  839. X   sprintf( nmbuff, GRNNAME, master_filename );
  840. X   if ((fgrn = fopen(nmbuff, "wb")) == NULL) {
  841. X      printf ("Cannot open green output file for %s\n", master_filename);
  842. X      exit(1);
  843. X      }
  844. X
  845. X   sprintf( nmbuff, BLUNAME, master_filename );
  846. X   if ((fblu = fopen(nmbuff, "wb")) == NULL) {
  847. X      printf ("Cannot open blue output file for %s\n", master_filename);
  848. X      exit(1);
  849. X      }
  850. X}
  851. X
  852. Xvoid SaveRGB(red, grn, blu)
  853. Xint red, grn, blu;
  854. X{
  855. X   fputc( red, fred );
  856. X   fputc( grn, fgrn );
  857. X   fputc( blu, fblu );
  858. X}
  859. X
  860. Xvoid read_raw_image(Image)
  861. X   IMAGE *Image;
  862. X   {
  863. X   FILE *f;
  864. X   unsigned int i, index, pixels;
  865. X   int byte, row;
  866. X
  867. X   if ((f = fopen(input_filename, "rb")) == NULL) {
  868. X      printf ("Cannot open raw file %s\n", input_filename);
  869. X      exit(1);
  870. X      }
  871. X
  872. X   Image->width = read_raw_word(f);
  873. X   if (Image->width == -1) {
  874. X      printf ("Cannot read size in dump file\n");
  875. X      exit(1);
  876. X      }
  877. X
  878. X   Image->height = read_raw_word(f);
  879. X   if (Image->height == -1) {
  880. X      printf ("Cannot read size in dump file: %s\n", input_filename);
  881. X      exit(1);
  882. X      }
  883. X
  884. X   pixels = Image->width * Image->height;
  885. X
  886. X   if (((Image->red = (unsigned char *) malloc(pixels))==NULL) ||
  887. X       ((Image->green = (unsigned char *) malloc(pixels))==NULL) ||
  888. X       ((Image->blue = (unsigned char *) malloc(pixels))==NULL)) {
  889. X      printf ("Cannot allocate memory for picture: %s\n", input_filename);
  890. X      exit(1);
  891. X      }
  892. X
  893. X   for (i = 0 ; i < pixels ; i++) {
  894. X      Image->red[i] = 0;
  895. X      Image->green[i] = 0;
  896. X      Image->blue[i] = 0;
  897. X      }
  898. X
  899. X   row = read_raw_word(f);
  900. X   while (row != -1) {
  901. X      for (i = 0 ; i < Image->width ; i++) {
  902. X         index = row*Image->width + i;
  903. X
  904. X         byte = read_raw_byte(f);
  905. X         if (byte == -1) {
  906. X            printf ("Unexpected end of file in raw image: %s\n", input_filename);
  907. X            exit(1);
  908. X            }
  909. X         Image->red[index] = byte;
  910. X         }
  911. X
  912. X      for (i = 0 ; i < Image->width ; i++) {
  913. X         index = row*Image->width + i;
  914. X
  915. X         byte = read_raw_byte(f);
  916. X         if (byte == -1) {
  917. X            printf ("Unexpected end of file in raw image: %s\n", input_filename);
  918. X            exit(1);
  919. X            }
  920. X         Image->green[index] = byte;
  921. X         }
  922. X
  923. X      for (i = 0 ; i < Image->width ; i++) {
  924. X         index = row*Image->width + i;
  925. X
  926. X         byte = read_raw_byte(f);
  927. X         if (byte == -1) {
  928. X            printf ("Unexpected end of file in raw image: %s\n", input_filename);
  929. X            exit(1);
  930. X            }
  931. X         Image->blue[index] = byte;
  932. X         }
  933. X      row = read_raw_word(f);
  934. X      }
  935. X   fclose (f);
  936. X   }
  937. END_OF_FILE
  938. if test 5693 -ne `wc -c <'src/Dump2RGB.c'`; then
  939.     echo shar: \"'src/Dump2RGB.c'\" unpacked with wrong size!
  940. fi
  941. # end of 'src/Dump2RGB.c'
  942. fi
  943. if test -f 'src/gio.c' -a "${1}" != "-c" ; then 
  944.   echo shar: Will not clobber existing file \"'src/gio.c'\"
  945. else
  946. echo shar: Extracting \"'src/gio.c'\" \(4579 characters\)
  947. sed "s/^X//" >'src/gio.c' <<'END_OF_FILE'
  948. X/*----------------------------------------------------------------------*/
  949. X/* GIO.C  Generic I/O Speed Up Package                         1/23/86  */
  950. X/* See GIOCall.C for an example of usage.                */
  951. X/* Read not speeded-up yet.  Only one Write file buffered at a time.    */
  952. X/* Note: The speed-up provided is ONLY significant for code such as IFF */
  953. X/* which does numerous small Writes and Seeks.                */
  954. X/*                                                                  */
  955. X/* By Jerry Morrison and Steve Shaw, Electronic Arts.               */
  956. X/* This software is in the public domain.                           */
  957. X/*                                                                  */
  958. X/* This version for the Commodore-Amiga computer.                   */
  959. X/*                                                                   */
  960. X/*----------------------------------------------------------------------*/
  961. X#include "iff/gio.h"    /* See comments here for explanation.*/
  962. X
  963. X#if GIO_ACTIVE
  964. X
  965. X#define local static
  966. X
  967. X
  968. Xlocal BPTR wFile      = NULL;
  969. Xlocal BYTE *wBuffer   = NULL;
  970. Xlocal LONG wNBytes    = 0; /* buffer size in bytes.*/
  971. Xlocal LONG wIndex     = 0; /* index of next available byte.*/
  972. Xlocal LONG wWaterline = 0; /* Count of # bytes to be written.
  973. X                * Different than wIndex because of GSeek.*/
  974. X
  975. X/*----------- GOpen ----------------------------------------------------*/
  976. XLONG GOpen(filename, openmode)   char *filename;  LONG openmode; {
  977. X    return( Open(filename, openmode) );
  978. X    }
  979. X
  980. X/*----------- GClose ---------------------------------------------------*/
  981. XLONG GClose(file)  BPTR file; {
  982. X    LONG signal = 0, signal2;
  983. X    if (file == wFile)
  984. X    signal = GWriteUndeclare(file);
  985. X    signal2 = Close(file);    /* Call Close even if trouble with write.*/
  986. X    if (signal2 < 0)
  987. X    signal = signal2;
  988. X    return( signal );
  989. X    }
  990. X
  991. X/*----------- GRead ----------------------------------------------------*/
  992. XLONG GRead(file, buffer, nBytes)   BPTR file;  BYTE *buffer;  LONG nBytes; {
  993. X    LONG signal = 0;
  994. X    /* We don't yet read directly from the buffer, so flush it to disk and
  995. X     * let the DOS fetch it back. */
  996. X    if (file == wFile)
  997. X    signal = GWriteFlush(file);
  998. X    if (signal >= 0)
  999. X    signal = Read(file, buffer, nBytes);
  1000. X    return( signal );
  1001. X    }
  1002. X
  1003. X/* ---------- GWriteFlush ----------------------------------------------*/
  1004. XLONG GWriteFlush(file)  BPTR file; {
  1005. X    LONG gWrite = 0;
  1006. X    if (wFile != NULL  &&  wBuffer != NULL  &&  wIndex > 0)
  1007. X    gWrite = Write(wFile, wBuffer, wWaterline);
  1008. X    wWaterline = wIndex = 0;    /* No matter what, make sure this happens.*/
  1009. X    return( gWrite );
  1010. X    }
  1011. X
  1012. X/* ---------- GWriteDeclare --------------------------------------------*/
  1013. XLONG GWriteDeclare(file, buffer, nBytes)
  1014. X    BPTR file;  BYTE *buffer;  LONG nBytes; {
  1015. X    LONG gWrite = GWriteFlush(wFile);  /* Finish any existing usage.*/
  1016. X    if ( file==NULL  ||  (file==wFile  &&  buffer==NULL)  ||  nBytes<=3) {
  1017. X    wFile = NULL;   wBuffer = NULL;     wNBytes = 0; }
  1018. X    else {
  1019. X    wFile = file;   wBuffer = buffer;   wNBytes = nBytes; }
  1020. X    return( gWrite );
  1021. X    }
  1022. X
  1023. X/* ---------- GWrite ---------------------------------------------------*/
  1024. XLONG GWrite(file, buffer, nBytes)   BPTR file;  BYTE *buffer;  LONG nBytes; {
  1025. X    LONG gWrite = 0;
  1026. X
  1027. X    if (file == wFile  &&  wBuffer != NULL) {
  1028. X    if (wNBytes >= wIndex + nBytes) {
  1029. X        /* Append to wBuffer.*/
  1030. X        movmem(buffer, wBuffer+wIndex, nBytes);
  1031. X        wIndex += nBytes;
  1032. X        if (wIndex > wWaterline)
  1033. X        wWaterline = wIndex;
  1034. X        nBytes = 0;        /* Indicate data has been swallowed.*/
  1035. X        }
  1036. X    else {
  1037. X        wWaterline = wIndex;     /* We are about to overwrite any
  1038. X        * data above wIndex, up to at least the buffer end.*/
  1039. X        gWrite = GWriteFlush(file);  /* Write data out in proper order.*/
  1040. X        }
  1041. X    }
  1042. X    if (nBytes > 0  &&  gWrite >= 0)
  1043. X    gWrite += Write(file, buffer, nBytes);
  1044. X    return( gWrite );
  1045. X    }
  1046. X
  1047. X/* ---------- GSeek ----------------------------------------------------*/
  1048. XLONG GSeek(file, position, mode)
  1049. X    BPTR file;   LONG position;   LONG mode; {
  1050. X    LONG gSeek = -2;
  1051. X    LONG newWIndex = wIndex + position;
  1052. X
  1053. X    if (file == wFile  &&  wBuffer != NULL) {
  1054. X    if (mode == OFFSET_CURRENT  &&
  1055. X        newWIndex >= 0  &&  newWIndex <= wWaterline) {
  1056. X        gSeek = wIndex;     /* Okay; return *OLD* position */
  1057. X        wIndex = newWIndex;
  1058. X        }
  1059. X    else {
  1060. X        /* We don't even try to optimize the other cases.*/
  1061. X        gSeek = GWriteFlush(file);
  1062. X        if (gSeek >= 0)   gSeek = -2;  /* OK so far */
  1063. X        }
  1064. X    }
  1065. X    if (gSeek == -2)
  1066. X    gSeek = Seek(file, position, mode);
  1067. X    return( gSeek );
  1068. X    }
  1069. X
  1070. X#else /* not GIO_ACTIVE */
  1071. X
  1072. Xvoid GIODummy() { }    /* to keep the compiler happy */
  1073. X
  1074. X#endif GIO_ACTIVE
  1075. END_OF_FILE
  1076. if test 4579 -ne `wc -c <'src/gio.c'`; then
  1077.     echo shar: \"'src/gio.c'\" unpacked with wrong size!
  1078. fi
  1079. # end of 'src/gio.c'
  1080. fi
  1081. if test -f 'src/ilbmw.c' -a "${1}" != "-c" ; then 
  1082.   echo shar: Will not clobber existing file \"'src/ilbmw.c'\"
  1083. else
  1084. echo shar: Extracting \"'src/ilbmw.c'\" \(5438 characters\)
  1085. sed "s/^X//" >'src/ilbmw.c' <<'END_OF_FILE'
  1086. X/*----------------------------------------------------------------------*
  1087. X * ILBMW.C  Support routines for writing ILBM files.            1/23/86
  1088. X * (IFF is Interchange Format File.)
  1089. X *
  1090. X * By Jerry Morrison and Steve Shaw, Electronic Arts.
  1091. X * This software is in the public domain.
  1092. X *
  1093. X * This version for the Commodore-Amiga computer.
  1094. X *----------------------------------------------------------------------*/
  1095. X#include "iff/packer.h"
  1096. X#include "iff/ilbm.h"
  1097. X#include <graphics/view.h>
  1098. X
  1099. X/*---------- InitBMHdr -------------------------------------------------*/
  1100. XIFFP InitBMHdr(bmHdr0, bitmap, masking, compression, transparentColor,
  1101. X        pageWidth, pageHeight)
  1102. X        BitMapHeader *bmHdr0;  struct BitMap *bitmap;
  1103. X        WORD masking;        /* Masking */
  1104. X    WORD compression;    /* Compression */
  1105. X    WORD transparentColor;    /* UWORD */
  1106. X    WORD pageWidth, pageHeight;
  1107. X    {
  1108. X    register BitMapHeader *bmHdr = bmHdr0;
  1109. X    register WORD rowBytes = bitmap->BytesPerRow;
  1110. X
  1111. X    bmHdr->w = rowBytes << 3;
  1112. X    bmHdr->h = bitmap->Rows;
  1113. X    bmHdr->x = bmHdr->y = 0;    /* Default position is (0,0).*/
  1114. X    bmHdr->nPlanes = bitmap->Depth;
  1115. X    bmHdr->masking = masking;
  1116. X    bmHdr->compression = compression;
  1117. X    bmHdr->pad1 = 0;
  1118. X    bmHdr->transparentColor = transparentColor;
  1119. X    bmHdr->xAspect = bmHdr->yAspect = 1;
  1120. X    bmHdr->pageWidth = pageWidth;
  1121. X    bmHdr->pageHeight = pageHeight;
  1122. X
  1123. X    if (pageWidth < 360)
  1124. X    if (pageHeight < 250) {
  1125. X           bmHdr->xAspect = x320x200Aspect;
  1126. X       bmHdr->yAspect = y320x200Aspect;
  1127. X           }
  1128. X        else {
  1129. X           bmHdr->xAspect = x320x400Aspect;
  1130. X       bmHdr->yAspect = y320x400Aspect;
  1131. X           }
  1132. X    else
  1133. X    if (pageHeight < 250) {
  1134. X           bmHdr->xAspect = x640x200Aspect;
  1135. X       bmHdr->yAspect = y640x200Aspect;
  1136. X           }
  1137. X    else {
  1138. X          bmHdr->xAspect = x640x400Aspect;
  1139. X      bmHdr->yAspect = y640x400Aspect; 
  1140. X          }
  1141. X
  1142. X    return( IS_ODD(rowBytes) ? CLIENT_ERROR : IFF_OKAY );
  1143. X    }
  1144. X
  1145. X/*---------- PutCMAP ---------------------------------------------------*/
  1146. XIFFP PutCMAP(context, vp)
  1147. X      GroupContext *context;
  1148. X      struct ViewPort *vp;
  1149. X   {
  1150. X   IFFP iffp;
  1151. X   ColorRegister colorReg;
  1152. X   int nColorRegs;
  1153. X   UWORD *CMapEntry;
  1154. X   struct ColorMap *colorMap;
  1155. X
  1156. X   colorMap = vp->ColorMap;
  1157. X   nColorRegs = colorMap->Count;
  1158. X
  1159. X   if ((vp->Modes & HIRES) && (nColorRegs > 16))
  1160. X      nColorRegs = 16;
  1161. X
  1162. X   if ((vp->Modes & HAM) && (nColorRegs > 16))
  1163. X      nColorRegs = 16;
  1164. X
  1165. X   iffp = PutCkHdr(context, ID_CMAP, nColorRegs * sizeofColorRegister);
  1166. X   CheckIFFP();
  1167. X
  1168. X   CMapEntry = (UWORD *)colorMap->ColorTable;
  1169. X
  1170. X   for (;  nColorRegs;  --nColorRegs)  {
  1171. X      colorReg.red   = ( *CMapEntry >> 4 ) & 0xf0;
  1172. X      colorReg.green = ( *CMapEntry      ) & 0xf0;
  1173. X      colorReg.blue  = ( *CMapEntry << 4 ) & 0xf0;
  1174. X      iffp = IFFWriteBytes(context, (BYTE *)&colorReg, sizeofColorRegister);
  1175. X      CheckIFFP();
  1176. X      CMapEntry++;
  1177. X      }
  1178. X
  1179. X   iffp = PutCkEnd(context);
  1180. X   return(iffp);
  1181. X   }
  1182. X
  1183. XIFFP PutCAMG(context, mode)
  1184. X      GroupContext *context;
  1185. X      LONG mode;   
  1186. X   {
  1187. X   IFFP iffp;
  1188. X   int CAMG_Size = 4;
  1189. X
  1190. X   iffp = PutCkHdr(context, ID_CAMG, 4L);
  1191. X   CheckIFFP();
  1192. X
  1193. X   iffp = IFFWriteBytes(context, (BYTE *)&mode, CAMG_Size);
  1194. X   CheckIFFP();
  1195. X
  1196. X   iffp = PutCkEnd(context);
  1197. X   return(iffp);
  1198. X   }
  1199. X
  1200. X/*---------- PutBODY ---------------------------------------------------*/
  1201. X/* NOTE: This implementation could be a LOT faster if it used more of the
  1202. X * supplied buffer. It would make far fewer calls to IFFWriteBytes (and
  1203. X * therefore to DOS Write). */
  1204. XIFFP PutBODY(context, bitmap, mask, bmHdr, buffer, bufsize)
  1205. X      GroupContext *context;  struct BitMap *bitmap;  BYTE *mask;
  1206. X      BitMapHeader *bmHdr;  BYTE *buffer;  LONG bufsize;
  1207. X   {         
  1208. X   IFFP iffp;
  1209. X   LONG rowBytes = bitmap->BytesPerRow;
  1210. X   int dstDepth = bmHdr->nPlanes;
  1211. X   Compression compression = bmHdr->compression;
  1212. X   int planeCnt;        /* number of bit planes including mask */
  1213. X   register int iPlane, iRow;
  1214. X   register LONG packedRowBytes;
  1215. X   BYTE *buf;
  1216. X   BYTE *planes[MaxAmDepth + 1]; /* array of ptrs to planes & mask */
  1217. X
  1218. X   if ( bufsize < MaxPackedSize(rowBytes)  ||    /* Must buffer a comprsd row*/
  1219. X        compression > cmpByteRun1  ||        /* bad arg */
  1220. X    bitmap->Rows != bmHdr->h   ||        /* inconsistent */
  1221. X    rowBytes != RowBytes(bmHdr->w)  ||    /* inconsistent*/
  1222. X    bitmap->Depth < dstDepth   ||        /* inconsistent */
  1223. X    dstDepth > MaxAmDepth )            /* too many for this routine*/
  1224. X      return(CLIENT_ERROR);
  1225. X
  1226. X   planeCnt = dstDepth + (mask == NULL ? 0 : 1);
  1227. X
  1228. X   /* Copy the ptrs to bit & mask planes into local array "planes" */
  1229. X   for (iPlane = 0; iPlane < dstDepth; iPlane++)
  1230. X      planes[iPlane] = (BYTE *)bitmap->Planes[iPlane];
  1231. X   if (mask != NULL)
  1232. X      planes[dstDepth] = mask;
  1233. X
  1234. X   /* Write out a BODY chunk header */
  1235. X   iffp = PutCkHdr(context, ID_BODY, szNotYetKnown);
  1236. X   CheckIFFP();
  1237. X
  1238. X   /* Write out the BODY contents */
  1239. X   for (iRow = bmHdr->h; iRow > 0; iRow--)  {
  1240. X      for (iPlane = 0; iPlane < planeCnt; iPlane++)  {
  1241. X
  1242. X         /* Write next row.*/
  1243. X         if (compression == cmpNone) {
  1244. X            iffp = IFFWriteBytes(context, planes[iPlane], rowBytes);
  1245. X            planes[iPlane] += rowBytes;
  1246. X            }
  1247. X
  1248. X         /* Compress and write next row.*/
  1249. X         else {
  1250. X            buf = buffer;
  1251. X            packedRowBytes = PackRow(&planes[iPlane], &buf, rowBytes);
  1252. X            iffp = IFFWriteBytes(context, buffer, packedRowBytes);
  1253. X            }
  1254. X
  1255. X         CheckIFFP();
  1256. X         }
  1257. X      }
  1258. X
  1259. X   /* Finish the chunk */
  1260. X   iffp = PutCkEnd(context);
  1261. X   return(iffp);
  1262. X   }
  1263. END_OF_FILE
  1264. if test 5438 -ne `wc -c <'src/ilbmw.c'`; then
  1265.     echo shar: \"'src/ilbmw.c'\" unpacked with wrong size!
  1266. fi
  1267. # end of 'src/ilbmw.c'
  1268. fi
  1269. if test -f 'src/makefile' -a "${1}" != "-c" ; then 
  1270.   echo shar: Will not clobber existing file \"'src/makefile'\"
  1271. else
  1272. echo shar: Extracting \"'src/makefile'\" \(6233 characters\)
  1273. sed "s/^X//" >'src/makefile' <<'END_OF_FILE'
  1274. X# Makefile for DKB Ray Tracing Program by David Buck and Aaron Collins
  1275. X# This file is released to the public domain.
  1276. X#
  1277. X#
  1278. X# MAKE Macros and Such...
  1279. X#
  1280. X
  1281. X#***************************************************************
  1282. X#*
  1283. X#*                      Amiga Options
  1284. X#*
  1285. X#***************************************************************
  1286. X
  1287. X# Uncomment for Amiga Lattice C FFP
  1288. X#CFLAGS    = -cusrft -ff -m0 -q5w5e -b0 -O -v
  1289. XDUMPFLAGS    = -cusrt -ff -m0 -q5w5e -O -v
  1290. X
  1291. X# Uncomment for Amiga Lattice C with 68881
  1292. XCFLAGS    = -cusrft -f8 -m2 -q5w5e -b0 -O -v
  1293. X
  1294. X# Flags for debugging
  1295. X# CFLAGS    = -cusrft -f8 -m2 -b0 -q5w5e -d5 -v
  1296. X
  1297. XLIBSFFP    = lib:lcmffp.lib lib:lcnb.lib lib:amiga.lib
  1298. XLIBS881    = lib:lcm881.lib lib:lcnb.lib lib:amiga.lib
  1299. XOBJ    = o
  1300. XMACHINE_OBJ    = amiga.$(OBJ)
  1301. X
  1302. X
  1303. X# Make's implicit rules for making a .o file from a .c file...
  1304. X#
  1305. X#.c.o :
  1306. X#    $(CC) $(CFLAGS) $*
  1307. X
  1308. X# Generic "Unix" MAKE's implicit rules for making a .OBJ file from a .C file
  1309. X#
  1310. X#*.o : *.c
  1311. X# $(CC) $(CFLAGS) $*
  1312. X
  1313. X#***************************************************************
  1314. X#*
  1315. X#*                      IBM Options
  1316. X#*
  1317. X#***************************************************************
  1318. X
  1319. X# Note for the IBM Version:
  1320. X# Uses system environment variable LIB for the linker's .LIB file path.
  1321. X# (Example:  Set LIB=C:\LIB)  if you change this the two .LNK files will also
  1322. X# need to be changed as well.  The system environment variable CMODEL also
  1323. X# may be defined for the memory model of the compiler.  DKBTrace requires
  1324. X# the "Large" memory model.  (Example Set CMODEL=l)  If you don't want to
  1325. X# use the DOS environment variables, uncomment the following two lines:
  1326. X
  1327. X#CMODEL    =l
  1328. X#LIB    =c:\lib
  1329. X
  1330. X#CC    =tcc
  1331. X#OBJ    =obj
  1332. X#MACHINE_OBJ    = ibm.$(OBJ)
  1333. X#
  1334. X# Uncomment Turbo Link for Symbolic Debugging, or use DOS/MS-LINK for
  1335. X# faster .EXE execution speed (shame on you, Borland, for no FARCALL!...)
  1336. X# Note: you also must use a -v in the CFLAGS rather than -v- if you want
  1337. X# to use the symbolic debugging facilities of Turbo-Debug.
  1338. X
  1339. X#TLINK    =tlink /l/v
  1340. X#TLINK    =link /EXEPACK /PACKCODE /FARCALL
  1341. X#
  1342. X# IBM (Turbo-MAKE, actually) Specific MAKE Directives:
  1343. X#
  1344. X#
  1345. X# Uncomment This for No Numeric Data Processor Extension (No Math Co)
  1346. X#LINKFLAGS=$(LIB)\emu+$(LIB)\math$(CMODEL)+$(LIB)\c$(CMODEL);
  1347. X#
  1348. X# Uncomment This for NDP Extension (80x87 Co-Processor) Support
  1349. X#LINKFLAGS=$(LIB)\fp87+$(LIB)\math$(CMODEL)+$(LIB)\c$(CMODEL);
  1350. X#
  1351. X
  1352. X# Uncomment for 8086/8088 instruction set usage
  1353. X#
  1354. X#CFLAGS    =-m$(CMODEL) -r -K -G -O -Z -d -c -v- -k- -N-
  1355. X
  1356. X
  1357. X# Uncomment for 80186/80268 (incl. V20!) instruction set usage
  1358. X#
  1359. X#CFLAGS    =-m$(CMODEL) -1 -a -r -K -G -O -Z -d -c -v- -k- -N-
  1360. X
  1361. X# Turbo-MAKE's implicit rules for making a .OBJ file from a .C file...
  1362. X#
  1363. X#.c.obj :
  1364. X# $(CC) $(CFLAGS) $*
  1365. X
  1366. X# Generic "Unix" MAKE's implicit rules for making a .OBJ file from a .C file
  1367. X#
  1368. X#*.obj : *.c
  1369. X# $(CC) $(CFLAGS) $*
  1370. X
  1371. X
  1372. X#***************************************************************
  1373. X#*
  1374. X#*                          Common  Stuff
  1375. X#*
  1376. X#***************************************************************
  1377. X
  1378. XDKBOBJS = trace.$(OBJ) render.$(OBJ) tokenize.$(OBJ) parse.$(OBJ) \
  1379. X      objects.$(OBJ) spheres.$(OBJ) quadrics.$(OBJ) lighting.$(OBJ) \
  1380. X      prioq.$(OBJ) texture.$(OBJ) matrices.$(OBJ) csg.$(OBJ) \
  1381. X      colour.$(OBJ) viewpnt.$(OBJ) ray.$(OBJ) planes.$(OBJ) iff.$(OBJ) \
  1382. X      gif.$(OBJ) gifdecod.$(OBJ) triangle.$(OBJ) raw.$(OBJ) $(MACHINE_OBJ)
  1383. X
  1384. X
  1385. X#  Amiga Linkage...
  1386. X#
  1387. Xtrace881:    $(DKBOBJS)
  1388. X    blink with withfile LIB $(LIBS881) TO trace881
  1389. X
  1390. Xtraceffp:    $(DKBOBJS)
  1391. X    blink with withfile LIB $(LIBSFFP) TO traceffp
  1392. X
  1393. XSculpt2DKB:    Sculpt2DKB.o
  1394. X    blink lib:c.o Sculpt2DKB.o lib $(LIBSFFP) to Sculpt2DKB
  1395. X
  1396. X# IBM Linkage...
  1397. X#
  1398. Xdkb.exe : $(DKBOBJS)
  1399. X    $(TLINK) @dkb.lnk
  1400. X
  1401. XSculpt2DKB.exe : Sculpt2DKB.obj
  1402. X    $(TLINK) $(LIB)\c0$(CMODEL)+Sculpt2DKB,Sculpt2DKB,Sculpt2DKB/m,$(LINKFLAGS);
  1403. X
  1404. Xgluetga.exe : gluetga.obj
  1405. X    $(TLINK) $(LIB)\c0$(CMODEL)+gluetga,gluetga,gluetga/m,$(LINKFLAGS);
  1406. X
  1407. Xhalftga.exe : halftga.obj
  1408. X    $(TLINK) $(LIB)\c0$(CMODEL)+halftga,halftga,halftga/m,$(LINKFLAGS);
  1409. X
  1410. X#
  1411. X# Specific module/header dependencies for DKBtrace:
  1412. X#
  1413. X
  1414. XSculpt2DKB.$(OBJ) : Sculpt2DKB.c dkbproto.h frame.h
  1415. X
  1416. Xhalftga.$(OBJ) : halftga.c
  1417. X
  1418. Xgluetga.$(OBJ) : gluetga.c
  1419. X
  1420. Xtrace.$(OBJ) : trace.c dkbproto.h frame.h vector.h config.h
  1421. X
  1422. Xtokenize.$(OBJ) : tokenize.c dkbproto.h frame.h config.h
  1423. X
  1424. Xparse.$(OBJ) : parse.c dkbproto.h frame.h config.h
  1425. X
  1426. Xrender.$(OBJ) : render.c dkbproto.h frame.h vector.h config.h
  1427. X
  1428. Xlighting.$(OBJ) : lighting.c dkbproto.h frame.h vector.h config.h
  1429. X
  1430. Xprioq.$(OBJ) : prioq.c dkbproto.h frame.h config.h
  1431. X
  1432. Xtexture.$(OBJ) : texture.c dkbproto.h frame.h vector.h config.h
  1433. X
  1434. Xobjects.$(OBJ) : objects.c dkbproto.h frame.h vector.h config.h
  1435. X
  1436. Xspheres.$(OBJ) : spheres.c dkbproto.h frame.h vector.h config.h
  1437. X
  1438. Xplanes.$(OBJ) : planes.c dkbproto.h frame.h vector.h config.h
  1439. X
  1440. Xquadrics.$(OBJ) : quadrics.c dkbproto.h frame.h vector.h config.h
  1441. X
  1442. Xmatrices.$(OBJ) : matrices.c dkbproto.h frame.h vector.h config.h
  1443. X
  1444. Xcsg.$(OBJ) : csg.c dkbproto.h frame.h vector.h config.h
  1445. X
  1446. Xcolour.$(OBJ) : colour.c dkbproto.h frame.h config.h
  1447. X
  1448. Xviewpnt.$(OBJ) : viewpnt.c dkbproto.h frame.h vector.h config.h
  1449. X
  1450. Xray.$(OBJ) : ray.c dkbproto.h frame.h vector.h config.h
  1451. X
  1452. Xiff.$(OBJ) : iff.c dkbproto.h frame.h config.h
  1453. X
  1454. Xgif.$(OBJ) : gif.c dkbproto.h frame.h config.h
  1455. X
  1456. Xgifdecod.$(OBJ) : gifdecod.c dkbproto.h frame.h config.h
  1457. X
  1458. Xraw.$(OBJ) :    raw.c dkbproto.h frame.h config.h
  1459. X
  1460. Xtriangle.$(OBJ) : triangle.c dkbproto.h frame.h vector.h config.h
  1461. X
  1462. Xamiga.$(OBJ) :    amiga.c dkbproto.h frame.h config.h
  1463. X
  1464. Xibm.$(OBJ) :    ibm.c dkbproto.h frame.h config.h
  1465. X
  1466. Xunix.$(OBJ) :    unix.c dkbproto.h frame.h config.h
  1467. X
  1468. X
  1469. X#
  1470. X#
  1471. X#  Utilities
  1472. X#
  1473. X
  1474. X#  Amiga Linkage
  1475. X#
  1476. XDump2RGB:    Dump2RGB.o
  1477. X        blink lib:c.o Dump2RGB.o LIB $(LIBSFFP) TO Dump2RGB
  1478. X
  1479. XDump2Raw:    Dump2Raw.o
  1480. X        blink lib:c.o Dump2Raw.o LIB $(LIBSFFP) TO Dump2Raw
  1481. X
  1482. XDumpToIFF:    DumpToIFF.o palette.o showprioq.o gio.o iffw.o ilbmw.o putpict.o packer.o
  1483. X        blink with dumpwithfile LIB $(LIBSFFP) TO DumpToIFF
  1484. X
  1485. XDumpToIFF.o:    DumpToIFF.c
  1486. X        $(CC) $(DUMPFLAGS) $*
  1487. X
  1488. XDump2RGB.o:    Dump2RGB.c
  1489. X
  1490. XDump2Raw.o:    Dump2Raw.c
  1491. X
  1492. Xpalette.o:    palette.c showprioq.h
  1493. X        $(CC) $(DUMPFLAGS) $*
  1494. X
  1495. Xshowprioq.o:    showprioq.c showprioq.h
  1496. X        $(CC) $(DUMPFLAGS) $*
  1497. X
  1498. Xgio.o:        gio.c
  1499. X        $(CC) $(DUMPFLAGS) $*
  1500. X
  1501. Xiffw.o:        iffw.c
  1502. X        $(CC) $(DUMPFLAGS) $*
  1503. X
  1504. Xilbmw.o:        ilbmw.c
  1505. X        $(CC) $(DUMPFLAGS) $*
  1506. X
  1507. Xputpict.o:        putpict.c
  1508. X        $(CC) $(DUMPFLAGS) $*
  1509. X
  1510. Xpacker.o:        packer.c
  1511. X        $(CC) $(DUMPFLAGS) $*
  1512. END_OF_FILE
  1513. if test 6233 -ne `wc -c <'src/makefile'`; then
  1514.     echo shar: \"'src/makefile'\" unpacked with wrong size!
  1515. fi
  1516. # end of 'src/makefile'
  1517. fi
  1518. if test -f 'src/palette.c' -a "${1}" != "-c" ; then 
  1519.   echo shar: Will not clobber existing file \"'src/palette.c'\"
  1520. else
  1521. echo shar: Extracting \"'src/palette.c'\" \(5971 characters\)
  1522. sed "s/^X//" >'src/palette.c' <<'END_OF_FILE'
  1523. X/*****************************************************************************
  1524. X*
  1525. X*                                   dumproto.h
  1526. X*
  1527. X*   from DKBTrace (c) 1990  David Buck
  1528. X*
  1529. X*  This file contains routines to choose colour palettes for DumpToIFF
  1530. X*
  1531. X* This software is freely distributable. The source and/or object code may be
  1532. X* copied or uploaded to communications services so long as this notice remains
  1533. X* at the top of each file.  If any changes are made to the program, you must
  1534. X* clearly indicate in the documentation and in the programs startup message
  1535. X* who it was who made the changes. The documentation should also describe what
  1536. X* those changes were. This software may not be included in whole or in
  1537. X* part into any commercial package without the express written consent of the
  1538. X* author.  It may, however, be included in other public domain or freely
  1539. X* distributed software so long as the proper credit for the software is given.
  1540. X*
  1541. X* This software is provided as is without any guarantees or warranty. Although
  1542. X* the author has attempted to find and correct any bugs in the software, he
  1543. X* is not responsible for any damage caused by the use of the software.  The
  1544. X* author is under no obligation to provide service, corrections, or upgrades
  1545. X* to this package.
  1546. X*
  1547. X* Despite all the legal stuff above, if you do find bugs, I would like to hear
  1548. X* about them.  Also, if you have any comments or questions, you may contact me
  1549. X* at the following address:
  1550. X*
  1551. X*     David Buck
  1552. X*     22C Sonnet Cres.
  1553. X*     Nepean Ontario
  1554. X*     Canada, K2H 8W7
  1555. X*
  1556. X*  I can also be reached on the following bulleton boards:
  1557. X*
  1558. X*     ATX              (613) 526-4141
  1559. X*     OMX              (613) 731-3419
  1560. X*     Mystic           (613) 731-0088 or (613) 731-6698
  1561. X*
  1562. X*  Fidonet:   1:163/109.9
  1563. X*  Internet:  David_Buck@Carleton.CA
  1564. X*
  1565. X*
  1566. X*****************************************************************************/
  1567. X
  1568. X#include <stdio.h>
  1569. X#include <exec/types.h>
  1570. X#include "showprioq.h"
  1571. X#include "dumptoiff.h"
  1572. X#include "dumproto.h"
  1573. X
  1574. XULONG last_red = 0, last_green = 0, last_blue = 0;
  1575. Xint Close_Threshold;
  1576. X
  1577. X#define absdif(x,y) ((x>y) ? (x-y):(y-x))
  1578. X#define Make_Colour(x, y, z) ((x & 0xF) << 8) + ((y & 0xF) << 4) + (z & 0xF)
  1579. X
  1580. X#define extract_red(x) ((x & 0xF00) >> 8)
  1581. X#define extract_green(x) ((x & 0x0F0) >> 4)
  1582. X#define extract_blue(x) (x & 0x00F)
  1583. X
  1584. Xstruct prioq_struct *Colour_q;
  1585. Xstruct prioq_struct *pq_new();
  1586. X
  1587. X
  1588. Xextern UWORD ColourTbl[16];
  1589. X
  1590. Xvoid reset_colours ()
  1591. X  {
  1592. X  last_red = last_green = last_blue = 0;
  1593. X  }
  1594. X
  1595. Xint closeness(x, y)
  1596. X  int x, y;
  1597. X  {
  1598. X  int red, blue, green;
  1599. X
  1600. X  red = absdif(extract_red(x), extract_red(y));
  1601. X  blue = absdif (extract_blue(x), extract_blue(y));
  1602. X  green = absdif(extract_green(x), extract_green(y));
  1603. X  return (red+blue+green);
  1604. X  }
  1605. X
  1606. Xvoid start_recording_colours ()
  1607. X  {
  1608. X  Colour_q = pq_new (256, 4096);
  1609. X  if (Colour_q == NULL)
  1610. X    exit (0);
  1611. X
  1612. X  reset_colours();
  1613. X  }
  1614. X
  1615. Xvoid record_colours (new_red, new_green, new_blue)
  1616. X  int new_red, new_green, new_blue;
  1617. X  {
  1618. X  LONG delta_red, delta_green, delta_blue, match_quality;
  1619. X
  1620. X  delta_red = absdif (new_red, last_red);
  1621. X  delta_green = absdif (new_green, last_green);
  1622. X  delta_blue = absdif (new_blue, last_blue);
  1623. X
  1624. X  if (delta_red > delta_green)
  1625. X    if (delta_red > delta_blue) {
  1626. X      last_red = new_red;
  1627. X      match_quality = delta_green + delta_blue;
  1628. X      }
  1629. X    else {
  1630. X      last_blue = new_blue;
  1631. X      match_quality = delta_green + delta_red;
  1632. X      }
  1633. X  else
  1634. X    if (delta_green > delta_blue)
  1635. X      {
  1636. X      last_green = new_green;
  1637. X      match_quality = delta_red + delta_blue;
  1638. X      }
  1639. X    else {
  1640. X      last_blue = new_blue;
  1641. X      match_quality = delta_green + delta_red;
  1642. X      }
  1643. X
  1644. X    if (match_quality != 0)
  1645. X      pq_add (Colour_q, match_quality,
  1646. X              Make_Colour (new_red, new_green, new_blue));
  1647. X  }      
  1648. X
  1649. Xvoid choose_palette()
  1650. X  {
  1651. X  int i, j, colour, min_distance, temp_distance;
  1652. X  struct prioq_struct *post_pq;
  1653. X
  1654. X  post_pq = pq_new (32, 4096);
  1655. X
  1656. X  ColourTbl[0] = Make_Colour (0, 0, 0);
  1657. X  for (i=1 ; i < 16 ;) {
  1658. X    if (pq_get_highest_index (Colour_q) > pq_get_highest_index (post_pq))
  1659. X      {
  1660. X      colour = pq_get_highest_value (Colour_q);
  1661. X      pq_delete_highest (Colour_q);
  1662. X
  1663. X      min_distance = 255;
  1664. X      for (j = 0 ; j < i ; j++)
  1665. X       if ((temp_distance = closeness (ColourTbl[j], colour)) < min_distance)
  1666. X         min_distance = temp_distance;
  1667. X
  1668. X      if (min_distance < 5)
  1669. X        pq_add (post_pq, min_distance, colour);
  1670. X      else
  1671. X       ColourTbl[i++] = colour;
  1672. X      }
  1673. X    else
  1674. X      {
  1675. X      ColourTbl[i++] = pq_get_highest_value (post_pq);
  1676. X      pq_delete_highest (post_pq);
  1677. X      }
  1678. X    }
  1679. X  pq_free (Colour_q);
  1680. X  pq_free (post_pq);
  1681. X  }
  1682. X
  1683. Xint best_colour (new_red, new_blue, new_green)
  1684. X  int new_red, new_blue, new_green;
  1685. X  {
  1686. X  int i, match_quality, best_match, colour,
  1687. X      delta_red, delta_green, delta_blue, temp_match_quality;
  1688. X
  1689. X  delta_red = absdif (new_red, last_red);
  1690. X  delta_green = absdif (new_green, last_green);
  1691. X  delta_blue = absdif (new_blue, last_blue);
  1692. X
  1693. X  if (delta_red > delta_green)
  1694. X    if (delta_red > delta_blue) {
  1695. X      last_red = new_red;
  1696. X      colour = 0x20 + new_red;
  1697. X      match_quality = delta_green + delta_blue;
  1698. X      }
  1699. X    else {
  1700. X      last_blue = new_blue;
  1701. X      colour = 0x10 + new_blue;
  1702. X      match_quality = delta_green + delta_red;
  1703. X      }
  1704. X  else
  1705. X    if (delta_green > delta_blue)
  1706. X      {
  1707. X      last_green = new_green;
  1708. X      colour = 0x30 + new_green;
  1709. X      match_quality = delta_red + delta_blue;
  1710. X      }
  1711. X    else {
  1712. X      last_blue = new_blue;
  1713. X      colour = 0x10 + new_blue;
  1714. X      match_quality = delta_green + delta_red;
  1715. X      }
  1716. X
  1717. X  if (match_quality != 0)
  1718. X    for (i = 0 ; i < 16 ; i++)
  1719. X      if ((temp_match_quality =
  1720. X           closeness (ColourTbl[i],
  1721. X            Make_Colour (new_red, new_green, new_blue)))
  1722. X          < match_quality) {
  1723. X        match_quality = temp_match_quality;
  1724. X        colour = i;
  1725. X        last_red = extract_red (ColourTbl[i]);
  1726. X        last_green = extract_green (ColourTbl[i]);
  1727. X        last_blue = extract_blue (ColourTbl[i]);
  1728. X        }
  1729. X  return (colour);
  1730. X  }
  1731. X
  1732. END_OF_FILE
  1733. if test 5971 -ne `wc -c <'src/palette.c'`; then
  1734.     echo shar: \"'src/palette.c'\" unpacked with wrong size!
  1735. fi
  1736. # end of 'src/palette.c'
  1737. fi
  1738. if test -f 'src/prioq.c' -a "${1}" != "-c" ; then 
  1739.   echo shar: Will not clobber existing file \"'src/prioq.c'\"
  1740. else
  1741. echo shar: Extracting \"'src/prioq.c'\" \(5064 characters\)
  1742. sed "s/^X//" >'src/prioq.c' <<'END_OF_FILE'
  1743. X/*****************************************************************************
  1744. X*
  1745. X*                                    prioq.c
  1746. X*
  1747. X*   from DKBTrace (c) 1990  David Buck
  1748. X*
  1749. X*  This module implements a priority queue using a heap.
  1750. X*
  1751. X* This software is freely distributable. The source and/or object code may be
  1752. X* copied or uploaded to communications services so long as this notice remains
  1753. X* at the top of each file.  If any changes are made to the program, you must
  1754. X* clearly indicate in the documentation and in the programs startup message
  1755. X* who it was who made the changes. The documentation should also describe what
  1756. X* those changes were. This software may not be included in whole or in
  1757. X* part into any commercial package without the express written consent of the
  1758. X* author.  It may, however, be included in other public domain or freely
  1759. X* distributed software so long as the proper credit for the software is given.
  1760. X*
  1761. X* This software is provided as is without any guarantees or warranty. Although
  1762. X* the author has attempted to find and correct any bugs in the software, he
  1763. X* is not responsible for any damage caused by the use of the software.  The
  1764. X* author is under no obligation to provide service, corrections, or upgrades
  1765. X* to this package.
  1766. X*
  1767. X* Despite all the legal stuff above, if you do find bugs, I would like to hear
  1768. X* about them.  Also, if you have any comments or questions, you may contact me
  1769. X* at the following address:
  1770. X*
  1771. X*     David Buck
  1772. X*     22C Sonnet Cres.
  1773. X*     Nepean Ontario
  1774. X*     Canada, K2H 8W7
  1775. X*
  1776. X*  I can also be reached on the following bulleton boards:
  1777. X*
  1778. X*     ATX              (613) 526-4141
  1779. X*     OMX              (613) 731-3419
  1780. X*     Mystic           (613) 731-0088 or (613) 731-6698
  1781. X*
  1782. X*  Fidonet:   1:163/109.9
  1783. X*  Internet:  David_Buck@Carleton.CA
  1784. X*
  1785. X*  IBM Port by Aaron A. Collins. Aaron may be reached on the following BBS'es:
  1786. X*
  1787. X*     Lattice BBS                      (708) 916-1200
  1788. X*     The Information Exchange BBS     (708) 945-5575
  1789. X*     Stillwaters BBS                  (708) 403-2826
  1790. X*
  1791. X*****************************************************************************/
  1792. X
  1793. X#include "frame.h"
  1794. X#include "dkbproto.h"
  1795. X
  1796. X#define NUMBER_OF_PRIOQS 20
  1797. X#define NUMBER_OF_INTERSECTIONS 20
  1798. X
  1799. XPRIOQ *prioqs;
  1800. X
  1801. Xvoid pq_init ()
  1802. X   {
  1803. X   register int i;
  1804. X   PRIOQ *new_pq;
  1805. X
  1806. X   prioqs = NULL;
  1807. X
  1808. X   for (i = 0 ; i < NUMBER_OF_PRIOQS; i++)
  1809. X      {
  1810. X      if ((new_pq = (PRIOQ *) malloc (sizeof (PRIOQ))) == NULL) {
  1811. X         printf ("\nCannot allocate queues");
  1812. X         exit(1);
  1813. X         }
  1814. X      
  1815. X      new_pq -> next_pq = prioqs;
  1816. X      prioqs = new_pq;
  1817. X
  1818. X      if ((new_pq -> queue = (INTERSECTION *)
  1819. X            malloc (128 * sizeof (INTERSECTION))) == NULL) {
  1820. X         printf ("\nCannot allocate queue entries");
  1821. X         exit(1);
  1822. X         }
  1823. X      }
  1824. X   }
  1825. X
  1826. XPRIOQ *pq_alloc()
  1827. X   {
  1828. X   PRIOQ *allocated_queue;
  1829. X
  1830. X   if (prioqs == NULL) {
  1831. X      printf ("\nOut of prioqs");
  1832. X      exit(1);
  1833. X      }
  1834. X
  1835. X   allocated_queue = prioqs;
  1836. X   prioqs = allocated_queue -> next_pq;
  1837. X   return (allocated_queue);
  1838. X   }
  1839. X
  1840. Xvoid pq_free (pq)
  1841. X   PRIOQ *pq;
  1842. X   {
  1843. X   pq -> next_pq = prioqs;
  1844. X   prioqs = pq;
  1845. X   }
  1846. X
  1847. XPRIOQ *pq_new (index_size)
  1848. X   int index_size;
  1849. X   {
  1850. X   PRIOQ *pq;
  1851. X
  1852. X   if (index_size > 256)
  1853. X      return (NULL);
  1854. X
  1855. X   if ((pq = pq_alloc()) == NULL)
  1856. X      return (NULL);
  1857. X
  1858. X   pq -> queue_size = index_size;
  1859. X   pq -> current_entry = 0;
  1860. X   return (pq);
  1861. X   }
  1862. X
  1863. Xvoid pq_balance(q, entry_pos1)
  1864. X   PRIOQ *q;
  1865. X   unsigned int entry_pos1;
  1866. X   {
  1867. X   register INTERSECTION *entry1, *entry2;
  1868. X   INTERSECTION temp_entry;
  1869. X   register unsigned int entry_pos2;
  1870. X
  1871. X   entry1 = &q->queue[entry_pos1];
  1872. X
  1873. X   if ((entry_pos1 * 2 < q->queue_size)
  1874. X       && (entry_pos1 * 2 <= q -> current_entry))
  1875. X      {
  1876. X      if ((entry_pos1*2+1 > q->current_entry) ||
  1877. X          (q->queue[entry_pos1*2].Depth < q->queue[entry_pos1*2+1].Depth))
  1878. X         entry_pos2 = entry_pos1*2;
  1879. X      else
  1880. X         entry_pos2 = entry_pos1*2+1;
  1881. X
  1882. X      entry2 = &q->queue[entry_pos2];
  1883. X
  1884. X      if (entry1->Depth > entry2->Depth) {
  1885. X         temp_entry = *entry1;
  1886. X         *entry1 = *entry2;
  1887. X         *entry2 = temp_entry;
  1888. X         pq_balance (q, entry_pos2);
  1889. X         }
  1890. X      }
  1891. X
  1892. X   if (entry_pos1 / 2 >= 1 )
  1893. X      {
  1894. X      entry_pos2 = entry_pos1 / 2;
  1895. X      entry2 = &q->queue[entry_pos2];
  1896. X      if (entry1->Depth < entry2->Depth) {
  1897. X         temp_entry = *entry1;
  1898. X         *entry1 = *entry2;
  1899. X         *entry2 = temp_entry;
  1900. X         pq_balance (q, entry_pos2);
  1901. X         }
  1902. X      }
  1903. X   }
  1904. X
  1905. Xvoid pq_add (q, entry)
  1906. X   PRIOQ *q;
  1907. X   INTERSECTION *entry;
  1908. X   {
  1909. X   q -> current_entry++;
  1910. X   if (q -> current_entry >= q -> queue_size)
  1911. X      q -> current_entry--;
  1912. X
  1913. X   q -> queue [q -> current_entry] = *entry;
  1914. X   pq_balance (q, q -> current_entry);
  1915. X   }
  1916. X
  1917. XINTERSECTION *pq_get_highest(q)
  1918. X   PRIOQ *q;
  1919. X   {
  1920. X   if (q -> current_entry >= 1)
  1921. X      return (&(q -> queue[1]));
  1922. X   else
  1923. X      return (NULL);
  1924. X   }
  1925. X
  1926. Xint pq_is_empty(q)
  1927. X   PRIOQ *q;
  1928. X   {
  1929. X   if (q -> current_entry < 1)
  1930. X      return (TRUE);
  1931. X   else
  1932. X      return (FALSE);
  1933. X   }
  1934. X
  1935. Xvoid pq_delete_highest (q)
  1936. X   PRIOQ *q;
  1937. X   {
  1938. X   q -> queue[1] = q -> queue[q -> current_entry--];
  1939. X   pq_balance (q, 1);
  1940. X   }
  1941. X
  1942. END_OF_FILE
  1943. if test 5064 -ne `wc -c <'src/prioq.c'`; then
  1944.     echo shar: \"'src/prioq.c'\" unpacked with wrong size!
  1945. fi
  1946. # end of 'src/prioq.c'
  1947. fi
  1948. if test -f 'src/raw.c' -a "${1}" != "-c" ; then 
  1949.   echo shar: Will not clobber existing file \"'src/raw.c'\"
  1950. else
  1951. echo shar: Extracting \"'src/raw.c'\" \(4724 characters\)
  1952. sed "s/^X//" >'src/raw.c' <<'END_OF_FILE'
  1953. X/*****************************************************************************
  1954. X*
  1955. X*                                     raw.c
  1956. X*
  1957. X*   from DKBTrace (c) 1990  David Buck
  1958. X*
  1959. X*  This file implements code to read in the raw 24 bit files produced by
  1960. X*  the raytracer to use as texture maps.
  1961. X*
  1962. X* This software is freely distributable. The source and/or object code may be
  1963. X* copied or uploaded to communications services so long as this notice remains
  1964. X* at the top of each file.  If any changes are made to the program, you must
  1965. X* clearly indicate in the documentation and in the programs startup message
  1966. X* who it was who made the changes. The documentation should also describe what
  1967. X* those changes were. This software may not be included in whole or in
  1968. X* part into any commercial package without the express written consent of the
  1969. X* author.  It may, however, be included in other public domain or freely
  1970. X* distributed software so long as the proper credit for the software is given.
  1971. X*
  1972. X* This software is provided as is without any guarantees or warranty. Although
  1973. X* the author has attempted to find and correct any bugs in the software, he
  1974. X* is not responsible for any damage caused by the use of the software.  The
  1975. X* author is under no obligation to provide service, corrections, or upgrades
  1976. X* to this package.
  1977. X*
  1978. X* Despite all the legal stuff above, if you do find bugs, I would like to hear
  1979. X* about them.  Also, if you have any comments or questions, you may contact me
  1980. X* at the following address:
  1981. X*
  1982. X*     David Buck
  1983. X*     22C Sonnet Cres.
  1984. X*     Nepean Ontario
  1985. X*     Canada, K2H 8W7
  1986. X*
  1987. X*  I can also be reached on the following bulleton boards:
  1988. X*
  1989. X*     ATX              (613) 526-4141
  1990. X*     OMX              (613) 731-3419
  1991. X*     Mystic           (613) 731-0088 or (613) 731-6698
  1992. X*
  1993. X*  Fidonet:   1:163/109.9
  1994. X*  Internet:  David_Buck@Carleton.CA
  1995. X*
  1996. X*  IBM Port by Aaron A. Collins. Aaron may be reached on the following BBS'es:
  1997. X*
  1998. X*     Lattice BBS                      (708) 916-1200
  1999. X*     The Information Exchange BBS     (708) 945-5575
  2000. X*     Stillwaters BBS                  (708) 403-2826
  2001. X*
  2002. X*****************************************************************************/
  2003. X
  2004. X
  2005. X#include "frame.h"
  2006. X#include "dkbproto.h"
  2007. X
  2008. Xint read_raw_byte(f)
  2009. X   FILE *f;
  2010. X   {
  2011. X   int c;
  2012. X   if ((c = getc(f)) == EOF)
  2013. X      return (-1);
  2014. X   return (c);
  2015. X   }
  2016. X
  2017. Xint read_raw_word(f)
  2018. X   FILE *f;
  2019. X   {
  2020. X   int byte1, byte2;
  2021. X
  2022. X   byte1 = read_raw_byte(f);
  2023. X   if (byte1 == -1)
  2024. X      return(-1);
  2025. X
  2026. X   byte2 = read_raw_byte(f);
  2027. X   if (byte2 == -1)
  2028. X      return(-1);
  2029. X
  2030. X   return (byte1 + byte2*256);
  2031. X   }
  2032. X
  2033. Xvoid read_raw_image(Image, filename)
  2034. X   IMAGE *Image;
  2035. X   char *filename;
  2036. X   {
  2037. X   FILE *f;
  2038. X   int byte, i, index, row, pixels;
  2039. X
  2040. X   if ((f = fopen(filename, "rb")) == NULL) {
  2041. X      printf ("Cannot open raw file %s\n", filename);
  2042. X      exit(1);
  2043. X      }
  2044. X
  2045. X   Image->iwidth = read_raw_word(f);
  2046. X   if (Image->iwidth == -1) {
  2047. X      printf ("Cannot read size in dump file\n");
  2048. X      exit(1);
  2049. X      }
  2050. X
  2051. X   Image->width = (DBL)Image->iwidth;
  2052. X
  2053. X   Image->iheight = read_raw_word(f);
  2054. X   if (Image->iheight == -1) {
  2055. X      printf ("Cannot read size in dump file: %s\n", filename);
  2056. X      exit(1);
  2057. X      }
  2058. X
  2059. X   Image->height = (DBL)Image->iheight;
  2060. X
  2061. X   pixels = Image->iwidth * Image->iheight;
  2062. X
  2063. X   if (((Image->red = (unsigned char *) malloc(pixels))==NULL) ||
  2064. X       ((Image->green = (unsigned char *) malloc(pixels))==NULL) ||
  2065. X       ((Image->blue = (unsigned char *) malloc(pixels))==NULL)) {
  2066. X      printf ("Cannot allocate memory for picture: %s\n", filename);
  2067. X      exit(1);
  2068. X      }
  2069. X
  2070. X   for (i = 0 ; i < pixels ; i++) {
  2071. X      Image->red[i] = 0;
  2072. X      Image->green[i] = 0;
  2073. X      Image->blue[i] = 0;
  2074. X      }
  2075. X
  2076. X   row = read_raw_word(f);
  2077. X   while (row != -1) {
  2078. X      for (i = 0 ; i < Image->iwidth ; i++) {
  2079. X         index = (Image->iheight-row)*Image->iwidth + i;
  2080. X
  2081. X         byte = read_raw_byte(f);
  2082. X         if (byte == -1) {
  2083. X            printf ("Unexpected end of file in raw image: %s\n", filename);
  2084. X            exit(1);
  2085. X            }
  2086. X         Image->red[index] = byte;
  2087. X         }
  2088. X
  2089. X      for (i = 0 ; i < Image->iwidth ; i++) {
  2090. X         index = (Image->iheight-row)*Image->iwidth + i;
  2091. X         byte = read_raw_byte(f);
  2092. X         if (byte == -1) {
  2093. X            printf ("Unexpected end of file in raw image: %s\n", filename);
  2094. X            exit(1);
  2095. X            }
  2096. X         Image->green[index] = byte;
  2097. X         }
  2098. X
  2099. X      for (i = 0 ; i < Image->iwidth ; i++) {
  2100. X         index = (Image->iheight-row)*Image->iwidth + i;
  2101. X         byte = read_raw_byte(f);
  2102. X         if (byte == -1) {
  2103. X            printf ("Unexpected end of file in raw image: %s\n", filename);
  2104. X            exit(1);
  2105. X            }
  2106. X         Image->blue[index] = byte;
  2107. X         }
  2108. X      row = read_raw_word(f);
  2109. X      }
  2110. X   fclose (f);
  2111. X   }
  2112. END_OF_FILE
  2113. if test 4724 -ne `wc -c <'src/raw.c'`; then
  2114.     echo shar: \"'src/raw.c'\" unpacked with wrong size!
  2115. fi
  2116. # end of 'src/raw.c'
  2117. fi
  2118. if test -f 'src/showprioq.c' -a "${1}" != "-c" ; then 
  2119.   echo shar: Will not clobber existing file \"'src/showprioq.c'\"
  2120. else
  2121. echo shar: Extracting \"'src/showprioq.c'\" \(5813 characters\)
  2122. sed "s/^X//" >'src/showprioq.c' <<'END_OF_FILE'
  2123. X/*****************************************************************************
  2124. X*
  2125. X*                                  showprioq.c
  2126. X*
  2127. X*   from DKBTrace (c) 1990  David Buck
  2128. X*
  2129. X*  This file manages a priority queue for DumpToIFF
  2130. X*
  2131. X* This software is freely distributable. The source and/or object code may be
  2132. X* copied or uploaded to communications services so long as this notice remains
  2133. X* at the top of each file.  If any changes are made to the program, you must
  2134. X* clearly indicate in the documentation and in the programs startup message
  2135. X* who it was who made the changes. The documentation should also describe what
  2136. X* those changes were. This software may not be included in whole or in
  2137. X* part into any commercial package without the express written consent of the
  2138. X* author.  It may, however, be included in other public domain or freely
  2139. X* distributed software so long as the proper credit for the software is given.
  2140. X*
  2141. X* This software is provided as is without any guarantees or warranty. Although
  2142. X* the author has attempted to find and correct any bugs in the software, he
  2143. X* is not responsible for any damage caused by the use of the software.  The
  2144. X* author is under no obligation to provide service, corrections, or upgrades
  2145. X* to this package.
  2146. X*
  2147. X* Despite all the legal stuff above, if you do find bugs, I would like to hear
  2148. X* about them.  Also, if you have any comments or questions, you may contact me
  2149. X* at the following address:
  2150. X*
  2151. X*     David Buck
  2152. X*     22C Sonnet Cres.
  2153. X*     Nepean Ontario
  2154. X*     Canada, K2H 8W7
  2155. X*
  2156. X*  I can also be reached on the following bulleton boards:
  2157. X*
  2158. X*     ATX              (613) 526-4141
  2159. X*     OMX              (613) 731-3419
  2160. X*     Mystic           (613) 731-0088 or (613) 731-6698
  2161. X*
  2162. X*  Fidonet:   1:163/109.9
  2163. X*  Internet:  David_Buck@Carleton.CA
  2164. X*
  2165. X*
  2166. X*****************************************************************************/
  2167. X
  2168. X
  2169. X#include <stdio.h>
  2170. X#include <exec/types.h>
  2171. X#include "showprioq.h"
  2172. X#include "dumptoiff.h"
  2173. X#include "dumproto.h"
  2174. X
  2175. Xchar *malloc();
  2176. X
  2177. X
  2178. Xstruct prioq_struct *pq_new (index_size, value_size)
  2179. X  int index_size, value_size;
  2180. X  {
  2181. X  struct prioq_struct *pq;
  2182. X  unsigned char *tmp_array;
  2183. X  int i;
  2184. X
  2185. X  if (index_size > 256)
  2186. X    return (NULL);
  2187. X
  2188. X  if ((pq = (struct prioq_struct *) malloc
  2189. X        (sizeof (struct prioq_struct))) == NULL)
  2190. X    return (NULL);
  2191. X
  2192. X  if ((pq -> queue = (struct q_entry *)
  2193. X                  malloc (index_size * sizeof (struct q_entry))) == NULL)  {
  2194. X    free (pq);
  2195. X    return (NULL);
  2196. X    }
  2197. X    
  2198. X  if ((pq -> array = (unsigned char *) malloc (value_size)) == NULL) {
  2199. X    free (pq -> queue);
  2200. X    free (pq);
  2201. X    return (NULL);
  2202. X    }
  2203. X
  2204. X  for (i=0, tmp_array = pq -> array ; i<value_size ; i++, tmp_array++)
  2205. X    *tmp_array = 0;
  2206. X
  2207. X  pq -> queue_size = index_size;
  2208. X  pq -> array_size = value_size;
  2209. X  pq -> current_entry = 0;
  2210. X  return (pq);
  2211. X  }
  2212. X
  2213. Xvoid pq_add (q, index, value)
  2214. X  struct prioq_struct *q;
  2215. X  unsigned int index, value;
  2216. X  {
  2217. X  unsigned int existing_entry;
  2218. X
  2219. X  if (value >= q -> array_size)
  2220. X    return;
  2221. X
  2222. X  if ((existing_entry = pq_find_value(q, value)) != 0) {
  2223. X    if ((q -> queue[existing_entry].index) < index)
  2224. X      (q -> queue[existing_entry].index) = index;
  2225. X    pq_balance (q, existing_entry);
  2226. X    }
  2227. X  else {
  2228. X    q -> current_entry++;
  2229. X    if (q -> current_entry >= q -> queue_size) {
  2230. X      q -> current_entry--;
  2231. X      q -> array [q->queue[q->current_entry].value] = 0;
  2232. X      }
  2233. X
  2234. X    q -> queue [q -> current_entry].index = index;
  2235. X    q -> queue [q -> current_entry].value = value;
  2236. X    q -> array [value] = q -> current_entry;
  2237. X    pq_balance (q, q -> current_entry);
  2238. X    }
  2239. X  return;
  2240. X  }
  2241. X    
  2242. Xint pq_find_value (q, value)
  2243. X  struct prioq_struct *q;
  2244. X  unsigned int value;
  2245. X  {
  2246. X  if (value < q -> array_size)
  2247. X    return ((int) q -> array[value]);
  2248. X  else
  2249. X    return (0);
  2250. X  }
  2251. X
  2252. Xvoid pq_balance(q, entry_pos1)
  2253. X  struct prioq_struct *q;
  2254. X  unsigned int entry_pos1;
  2255. X  {
  2256. X  register struct q_entry *entry1, *entry2;
  2257. X  register unsigned int tmp_index, tmp_value, entry_pos2;
  2258. X
  2259. X  entry1 = &q->queue[entry_pos1];
  2260. X
  2261. X  if ((entry_pos1 * 2 < q->queue_size)
  2262. X      && (entry_pos1 * 2 <= q -> current_entry))
  2263. X    {
  2264. X    if ((entry_pos1*2+1 > q->current_entry) ||
  2265. X        (q->queue[entry_pos1*2].index > q->queue[entry_pos1*2+1].index))
  2266. X      entry_pos2 = entry_pos1*2;
  2267. X    else
  2268. X      entry_pos2 = entry_pos1*2+1;
  2269. X
  2270. X    entry2 = &q->queue[entry_pos2];
  2271. X
  2272. X    if (entry1->index < entry2->index) {
  2273. X      q -> array [entry1->value] = entry_pos2;
  2274. X      q -> array [entry2->value] = entry_pos1;
  2275. X
  2276. X      tmp_index = entry1->index;
  2277. X      entry1->index = entry2->index;
  2278. X      entry2->index = tmp_index;
  2279. X
  2280. X      tmp_value = entry1->value;
  2281. X      entry1->value = entry2->value;
  2282. X      entry2->value = tmp_value;
  2283. X
  2284. X      pq_balance (q, entry_pos2);
  2285. X      }
  2286. X    }
  2287. X
  2288. X  if (entry_pos1 / 2 >= 1 )
  2289. X    {
  2290. X    entry_pos2 = entry_pos1 / 2;
  2291. X    entry2 = &q->queue[entry_pos2];
  2292. X    if (entry1->index > entry2->index) {
  2293. X      q -> array [entry1->value] = entry_pos2;
  2294. X      q -> array [entry2->value] = entry_pos1;
  2295. X
  2296. X      tmp_index = entry1->index;
  2297. X      entry1->index = entry2->index;
  2298. X      entry2->index = tmp_index;
  2299. X
  2300. X      tmp_value = entry1->value;
  2301. X      entry1->value = entry2->value;
  2302. X      entry2->value = tmp_value;
  2303. X
  2304. X      pq_balance (q, entry_pos2);
  2305. X      }
  2306. X    }
  2307. X  }
  2308. X
  2309. Xint pq_get_highest_index(q)
  2310. X  struct prioq_struct *q;
  2311. X  {
  2312. X  if (q -> current_entry >= 1)
  2313. X    return ((int) q -> queue[1].index);
  2314. X  else
  2315. X    return (0);
  2316. X  }
  2317. X
  2318. Xint pq_get_highest_value(q)
  2319. X  struct prioq_struct *q;
  2320. X  {
  2321. X  if (q -> current_entry >= 1)
  2322. X    return ((int) q -> queue[1].value);
  2323. X  else
  2324. X    return (0);
  2325. X  }
  2326. X
  2327. Xvoid pq_delete_highest (q)
  2328. X  struct prioq_struct *q;
  2329. X  {
  2330. X  q -> queue[1].index = q -> queue[q -> current_entry].index;
  2331. X  q -> queue[1].value = q -> queue[q -> current_entry--].value;
  2332. X  pq_balance (q, 1);
  2333. X  }
  2334. X
  2335. Xvoid pq_free (q)
  2336. X  struct prioq_struct *q;
  2337. X  {
  2338. X  free (q ->queue);
  2339. X  free (q -> array);
  2340. X  free (q);
  2341. X  }
  2342. END_OF_FILE
  2343. if test 5813 -ne `wc -c <'src/showprioq.c'`; then
  2344.     echo shar: \"'src/showprioq.c'\" unpacked with wrong size!
  2345. fi
  2346. # end of 'src/showprioq.c'
  2347. fi
  2348. echo shar: End of archive 2 \(of 10\).
  2349. cp /dev/null ark2isdone
  2350. MISSING=""
  2351. for I in 1 2 3 4 5 6 7 8 9 10 ; do
  2352.     if test ! -f ark${I}isdone ; then
  2353.     MISSING="${MISSING} ${I}"
  2354.     fi
  2355. done
  2356. if test "${MISSING}" = "" ; then
  2357.     echo You have unpacked all 10 archives.
  2358.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2359. else
  2360.     echo You still need to unpack the following archives:
  2361.     echo "        " ${MISSING}
  2362. fi
  2363. ##  End of shell archive.
  2364. exit 0
  2365. -- 
  2366. Mail submissions (sources or binaries) to <amiga@uunet.uu.net>.
  2367. Mail comments to the moderator at <amiga-request@uunet.uu.net>.
  2368. Post requests for sources, and general discussion to comp.sys.amiga.
  2369.